I am using TeamCity and I am looking at how to get incremental instrumented android test results.
To run the tests I run ./gradlew :TestApp:connectedAndroidDebugTest --info
This gives me output of what tests are running and their state but the full report is only generated at the end.
How can I get incremental android test results in TeamCity? I can add custom logs that TeamCity will pick up, but I am unsure where to add them in the gradle build file.
Looks like, you are using Command Line runner step.
Try using Gradle runner step instead. You will get on-the-fly test reporting with it. TeamCity will display each test as soon as it is executed.
Related
I have a project using dynamic feature module, and I want to run my unit test in feature module via gradle task (for my CI purpose):
./gradlew :feature_product:test
But it always gives me NoClassDefFoundError for tests that have dependencies on classes from the base module:
com.example.android.feature.product.ProductViewTest > on vote change to negative FAILED
java.lang.NoClassDefFoundError: app.BaseView
ProductView class from the feature module extends BaseView from the base module.
Oddly, it succeeds when run in Android Studio, it works fine.
Then I notice something different in the logs, when I run via command line and when I run Android Studio. The first line in the Android Studio is generateDebugSources, something which absent when I run ./gradlew test
Executing tasks: [:lib_ui:generateDebugSources, ...]
How do I fix this? Does Android Studio has different command with the provided command ./gradlew test when I press Ctrl+Shift+R ?
After searching further about this issue, I found it also being reported in the android-test and app-bundle-samples projects and there is also an issue in the issue tracker.
It turns out this issue fixed in the Android Gradle Plugin 4.1.0 as per comment in the issue tracker.
If you don't want to update AGP to 4.1.0 which is still in alpha, adding this to the feature module's build.gradle fixed the issue for me, as per this comment:
testRuntimeOnly(files("$projectDir/../b_app/build/intermediates/app_classes/debug/classes.jar"))
If it is a missing task that you believe is necessary then calling it first like below should do the trick:
./gradlew :lib_ui:generateDebugSources :feature_product:test
I would even go full on and assemble the dependencies if necessary though that might take more time:
./gradlew :lib_ui:assemble :feature_product:assemble :feature_product:test
I am currently testing my sample app using Android instrumentation test. By default, the project creates AndroidTest folder for me. I simply just added more test cases into the folder.
I used to use expresso to trigger the UI buttons, but now I want to test use androidTest only, However, the androidTest does not seem to test my release build. I have two variants productionRelease and stageDebug in this case.
Every time I started the project by
./gradlew mysample:connectedCheck
or
./gradlew mysample:connectedAndroidTest
it tests only
Task :mysample:connectedStageDebugAndroidTest
If I want to manually start a task
./gradlew mysample:connectedProductionReleaeAndroidCheck
It complains tasks not found in mysample
* What went wrong:
Task 'connectedProductionReleaseAndroidTest' not found in project ':mysample'.
Isn't connectCheck supposed to test all the variants in my project? (StageDebug and ProductionRelease)
from task --all
mysample:connectedCheck - Runs all device checks on currently connected devices.
mysample:connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
Just tried... one can simply run ./gradlew mysample:testDebugUnitTest and ./gradlew mysample:testReleaseUnitTest - which runs the tests for either debug or release build. one can add the annotation #RequiresDevice to tests, in case eg. one requires hardware sensors.
productionRelease and stageDebug seem over-complicated (and it also not matches the rest of the naming - unless there would be productionDebug and stageRelease as well), resulting in even longer task names, would suggest to shorten...
buildTypes {
debug {}
release {}
}
Here when I run ./gradlew mysample:connectedAndroidTest I rather get a
Execution failed for task ':mysample:connectedDebugAndroidTest'.
com.android.builder.testing.api.DeviceException: No connected devices!
After closing Android Studio (and the ADB daemon it started), I can run the tests on hardware device. there only is a installDebugAndroidTest task, but no installReleaseAndroidTest task. testBuildType 'release' might run the tests against the release build - the problem is just that androidTestImplementation most likely is not contained then (quite useless).
I have Jenkins job that builds an apk. I also have a gradle command that will run some tests on an Android device. I would like my jenkins job to be able to run this gradle command, but if the tests fail I don't want jenkins to fail the entire build. I just want it to mark the tests as failing and then notify people that the tests have failed. But failing tests by themselves should not mark the whole build as a fail. Is there a way to do this?
I believe you use the ignoreFailures = true flag in your gradle.build's Test task config.
If that doesn't work, you can use Jenkins try/catch/finally:
try {
// test step here
} catch (error) {
// other steps if test step fails
}
Backstory:
Module A depends on Module B
Want to know the gradle command line
execution when Android Studio runs the unit test package for Module A
This is important because I'm trying to compare how it differs from executing tests from command line with:
./gradlew :testDebug
You see, when running the test package from Android Studio my tests run correctly, but running with command line above gradle throws an exception.
The root of the problem is that when run on command line gradle cannot find resource file for dependent Module B. Line that throws exception:
setParametersFromResource(context, R.raw.coursera_mobile_android, VALUE_NAMESPACE);
I knew before you can read the gradle executions via the Gradle Console, but didn't realize you can execute that bundle of commands via command line.
Example from Gradle console:
Execute [:<module_name>:assembleDebug, :<module_name>:assembleDebugUnitTest]
to:
./gradlew [:<module_name>:assembleDebug, :<module_name>:assembleDebugUnitTest]
I've currently set my TeamCity instance to run connectedCheck on all my Android-projects. This is fine, all tests run and everything is good. Except, connectedCheck runs all tests for all product flavors. I currently have a lot of flavors, so this is wasted work for my projects as I do not really have any different code in the flavors. Any idea how I can make connectedCheck only run for one flavor?
./gradlew connected[Flavor]DebugAndroidTest
./gradlew connectedBuildVariantAndroidTest
Example:
./gradlew connectedDevelopmentDebugAndroidTest
As vida said you can run ./gradlew tasks to check all possibilities to run gradle commands.
I'd like to suggest the following:
./gradlew tasks | grep connected.
This filter all connectedAndroidTest variants that can be runned.
I see there is a new task since I checked this the last time, "connectedAndroidTestProductFalvor_buildvariant".
I haven't had time to check this task yet, but the description reads "Installs and runs the tests for build ProductFlavor_buildvariant on connected devices."
Will post a result when I've been able to test this.
and if you want to generate the apk for the android test :
./gradlew assemble[flavour]DebugAndroidTest