Skip to content

Commit 6dc83b6

Browse files
authored
CATROID-1593 Fix error 'Could not launch activity' in Espresso tests (#5033)
Android OS can only start activities if they are listed in the app's Manifest. Activities created for testing purposes were therefore moved into the debug source set and listed in the corresponding debug Manifest. When the app us built for testing those activities will be available but not when the app is built for release.
1 parent 4155bb2 commit 6dc83b6

File tree

9 files changed

+86
-29
lines changed

9 files changed

+86
-29
lines changed

catroid/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ dependencies {
387387

388388

389389

390+
implementation "org.mockito:mockito-core:$mockitoVersion"
390391
implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
391392

392393
implementation ('com.opencsv:opencsv:5.0') {

catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/activity/ConnectBluetoothDeviceActivityTest.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
3333
import androidx.test.espresso.matcher.ViewMatchers.withId
3434
import androidx.test.espresso.matcher.ViewMatchers.withText
3535
import androidx.test.ext.junit.runners.AndroidJUnit4
36+
import org.catrobat.catroid.ui.ConnectBluetoothDeviceTestActivity
3637
import org.catrobat.catroid.R
37-
import org.catrobat.catroid.bluetooth.ConnectBluetoothDeviceActivity
3838
import org.catrobat.catroid.bluetooth.ConnectBluetoothDeviceActivity.DEVICE_TO_CONNECT
3939
import org.catrobat.catroid.bluetooth.base.BluetoothDevice.MULTIPLAYER
4040
import org.catrobat.catroid.common.SharedPreferenceKeys.SHOW_MULTIPLAYER_BLUETOOTH_DIALOG_KEY
@@ -119,9 +119,4 @@ class ConnectBluetoothDeviceActivityTest {
119119
.perform(click())
120120
.check(matches(withDrawable(R.drawable.ic_close)))
121121
}
122-
123-
class ConnectBluetoothDeviceTestActivity : ConnectBluetoothDeviceActivity() {
124-
override fun initBluetooth() = Unit
125-
override fun doDiscovery() = Unit
126-
}
127122
}

catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/activity/ProjectUploadDialogTest.kt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ import org.catrobat.catroid.content.Scene
4848
import org.catrobat.catroid.io.asynctask.saveProjectSerial
4949
import org.catrobat.catroid.ui.NUMBER_OF_UPLOADED_PROJECTS
5050
import org.catrobat.catroid.ui.PROJECT_DIR
51-
import org.catrobat.catroid.ui.ProjectUploadActivity
52-
import org.catrobat.catroid.ui.controller.ProjectUploadController
51+
import org.catrobat.catroid.ui.ProjectUploadTestActivity
5352
import org.catrobat.catroid.uiespresso.util.UiTestUtils
5453
import org.catrobat.catroid.uiespresso.util.rules.BaseActivityTestRule
5554
import org.junit.Assert.assertFalse
@@ -58,7 +57,6 @@ import org.junit.Rule
5857
import org.junit.Test
5958
import org.junit.runner.RunWith
6059
import org.mockito.Mockito
61-
import org.mockito.Mockito.spy
6260
import org.mockito.Mockito.verify
6361

6462
@RunWith(AndroidJUnit4::class)
@@ -237,17 +235,4 @@ class ProjectUploadDialogTest {
237235
val checkKeyboardCommand = "dumpsys input_method | grep mInputShown"
238236
return UiDevice.getInstance(getInstrumentation()).executeShellCommand(checkKeyboardCommand).contains("mInputShown=true")
239237
}
240-
241-
class ProjectUploadTestActivity : ProjectUploadActivity() {
242-
override fun createProjectUploadController(): ProjectUploadController? {
243-
projectUploadController = spy(ProjectUploadController(this))
244-
return projectUploadController
245-
}
246-
247-
override fun verifyUserIdentity() {
248-
onTokenCheckComplete(true, false)
249-
}
250-
251-
fun projectUploadController(): ProjectUploadController? = projectUploadController
252-
}
253238
}

catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/ReplaceApiKeyDialogTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import org.catrobat.catroid.content.Sprite;
4141
import org.catrobat.catroid.content.StartScript;
4242
import org.catrobat.catroid.content.bricks.BackgroundRequestBrick;
43-
import org.catrobat.catroid.uiespresso.ui.activity.ProjectUploadDialogTest;
43+
import org.catrobat.catroid.ui.ProjectUploadTestActivity;
4444
import org.catrobat.catroid.uiespresso.util.rules.BaseActivityTestRule;
4545
import org.junit.After;
4646
import org.junit.Before;
@@ -68,8 +68,8 @@ public class ReplaceApiKeyDialogTest {
6868
private static final String TAG = ReplaceApiKeyDialogTest.class.getSimpleName();
6969

7070
@Rule
71-
public BaseActivityTestRule<ProjectUploadDialogTest.ProjectUploadTestActivity> activityTestRule =
72-
new BaseActivityTestRule<>(ProjectUploadDialogTest.ProjectUploadTestActivity.class, false, false);
71+
public BaseActivityTestRule<ProjectUploadTestActivity> activityTestRule =
72+
new BaseActivityTestRule<>(ProjectUploadTestActivity.class, false, false);
7373

7474
private int bufferedPrivacyPolicyPreferenceSetting;
7575

catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/ReuploadProjectDialogTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import org.catrobat.catroid.formulaeditor.UserVariable
3939
import org.catrobat.catroid.io.XstreamSerializer
4040
import org.catrobat.catroid.io.asynctask.saveProjectSerial
4141
import org.catrobat.catroid.ui.PROJECT_DIR
42-
import org.catrobat.catroid.uiespresso.ui.activity.ProjectUploadDialogTest.ProjectUploadTestActivity
42+
import org.catrobat.catroid.ui.ProjectUploadTestActivity
4343
import org.catrobat.catroid.uiespresso.util.rules.BaseActivityTestRule
4444
import org.junit.After
4545
import org.junit.Rule

catroid/src/debug/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
tools:replace="android:label,android:allowBackup,android:name"
9292
android:usesCleartextTraffic="true">
9393

94+
<activity
95+
android:name=".ui.ConnectBluetoothDeviceTestActivity" />
96+
97+
<activity
98+
android:name=".ui.ProjectUploadTestActivity" />
9499
<!--
95100
<activity
96101
android:name=".ui.SettingsActivity"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Catroid: An on-device visual programming system for Android devices
3+
* Copyright (C) 2010-2024 The Catrobat Team
4+
* (<http://developer.catrobat.org/credits>)
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* An additional term exception under section 7 of the GNU Affero
12+
* General Public License, version 3, is available at
13+
* http://developer.catrobat.org/license_additional_term
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
package org.catrobat.catroid.ui
24+
25+
import org.catrobat.catroid.bluetooth.ConnectBluetoothDeviceActivity
26+
27+
class ConnectBluetoothDeviceTestActivity : ConnectBluetoothDeviceActivity() {
28+
override fun initBluetooth() = Unit
29+
override fun doDiscovery() = Unit
30+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Catroid: An on-device visual programming system for Android devices
3+
* Copyright (C) 2010-2024 The Catrobat Team
4+
* (<http://developer.catrobat.org/credits>)
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* An additional term exception under section 7 of the GNU Affero
12+
* General Public License, version 3, is available at
13+
* http://developer.catrobat.org/license_additional_term
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
24+
package org.catrobat.catroid.ui
25+
26+
import org.catrobat.catroid.ui.controller.ProjectUploadController
27+
import org.mockito.Mockito.spy
28+
29+
class ProjectUploadTestActivity : ProjectUploadActivity() {
30+
override fun createProjectUploadController(): ProjectUploadController? {
31+
projectUploadController = spy(ProjectUploadController(this))
32+
return projectUploadController
33+
}
34+
35+
override fun verifyUserIdentity() {
36+
onTokenCheckComplete(true, false)
37+
}
38+
39+
fun projectUploadController(): ProjectUploadController? = projectUploadController
40+
}

catroid/src/main/AndroidManifest.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@
7878

7979
<uses-feature
8080
android:glEsVersion="0x00020000"
81-
android:required="true" /><uses-feature
82-
android:name="android.hardware.camera"
83-
android:required="false" />
81+
android:required="true" />
82+
<uses-feature
83+
android:name="android.hardware.camera"
84+
android:required="false" />
8485

8586
<!-- foreground services -->
8687
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

0 commit comments

Comments
 (0)