I'm trying to test an Android app having 2 flavors.
I run them with gradlew connectedCheck
However if one test fails on the first flavor, then tests stop and the second flavor is never tested.
How can we make it continue with the 2nd flavour even if there was a failing test in the first?
Related
So I want to build my tests and app, and then run the instrumentation tests whenever I want, even when I do not have access to the code (and hence, cannot use cAT task)
I have tried using assembleAndroidTest to generate test apk. But when I install this apk (as well as the app apk) and run am instrumentation with correct arguments (-e emma true, and with correct runner class verified using pm list instrumentation), I get no .ec file under /data/app/<package-name>. There is no error however.
I am using JaCoCo and when I run the tests using cAT, the coverage report is generated so I guess my JaCoCo configs are Ok.
If I:
Create a brand-new Android Studio 3.5.1 project (Kotlin, API 21, "Empty Activity" template)
Run the app from inside the IDE
Confirm the app is installed and has a launcher icon
Run the connectedAndroidDebugTest Gradle task (from inside Android Studio or via gradlew)
The app winds up being uninstalled by the test run. I get that behavior even if I add a testApplicationId value to defaultConfig to have the test code use a different application ID.
How do I stop that behavior? How can I run instrumented tests from the command line, without disturbing an existing app installation?
The connectedCheck task has the type DeviceProviderInstrumentTestTask. For a simple test run on one device it uses a SimpleTestRunner, which in
turn uses a SimpleTestRunnable to actually execute the test. Here you find a structure of
try {
// connect to device
// install all APKs
// run tests
} catch(Exception e) {
// handle error
} finally {
// get test report
// uninstall all APKs
// disconnect from device
}
I'm not perfectly sure if I've found the most recent implementations, but this exact behavior dates back several years. So I guess you can't achieve what you're asking for.
Maybe try to run it via adb like this:
adb shell am instrument -w com.android.demo.app.tests/android.support.test.runner.AndroidJUnitRunner
It will not uninstall your app.
here it is described in more details.
The instrumentation installs 2 APKs: the APK under test and the APK with the test code.
It also uninstalls both APKs before it tries to install the new ones and I don't know if it's possible to prevent the uninstall itself.
testApplicationId changes only application id for the APK with the test code (which is normally the same as for the main APK with ".test" appended) the application id of the APK under test remains still the same. But it is possible to create separate buildType for the APK under test (with exactly the same configuration as the debug build type) and use that.
Then connectedAndroidXYZTest could be used to run the tests (or createXYZCoverageReport).
We're running CI server which runs checks for each commit.
./gradlew check
But it take ages, because it builds release build with ProGuard, etc. But when I try to run it with just debug variant, no tests and lint checks are run, it just finishes immediately.
./gradlew checkDebug
It's a bit WTF for me. How can we do that?
I have made a library project consisting of an Android module and no application. This module relies on Android-specific functionality.
How do I run these tests with Firebase?
It seems like Firebase requires an app apk and a test apk, while I only have a test apk (*-androidTest.apk). I normally run tests locally without issues using ./gradlew connectedCheck.
I have a web app that is using Firebase FCM to communicate with my android device.
On receiving a certain data message through Firebase, I need android to run Instrumentation tests (such tests are run in a separate test application or "test APK" which is developed in the androidTest folder).
How can I make an Intent that will launch the test APK?
You can't run instrumentation tests in response to an external stimulus like this. Instrumentation tests are always driven through a JUnit test harness, which requires yet some other controlling process to kick them off using the am instrument command line program on the device. This is typically Android Studio, which will install both your app APK and your test APK, then kick off the tests. Firebase Test Lab will also take both APKs kick off your tests on physical and virtual devices.