I have to following gradle code:
testOptions {
unitTests.returnDefaultValues = true
unitTests.all {
// All the usual Gradle options.
jvmArgs '-XX:MaxPermSize=1024m'
}
execution 'ANDROID_TEST_ORCHESTRATOR'
}
And I am using Android test orchestrator, but I makes my UI tests take a lot of time to run. So I would like to be able to request for orchestrator in the command line like:
./gradlew androidConnectedCheck --orchestrator
So I can controll when to use orchestator. Is it possible to do that with gradle?
Edit:
I am not interested in using a gradle variable in my code (in Java or Kotlin) I would like to create a conditional test configuration accordingly with my command line
./gradlew androidConnectedCheck -Porchestrator
And in gradle, you can do:
def orchestrator = project.hasProperty('orchestrator')
orchestrator will be true if it was passed as an arg. This uses the project-prop built into gradle command line.
Related
My build.gradle is like this:
productFlavors {
mainFlavor {
// ...
}
}
buildTypes {
debug {
// ...
}
buildType1 {// I write mock data classes for Espresso tests here
// ...
}
}
./gradlew tasks includes connectedMainFlavorDebugAndroidTest but not connectedMainFlavorBuildType1AndroidTest.
Why?
I want to specifically run Espresso tests for buildType1 only.
I'm not the owner of the project, I'm not allowed to use either mainFlavorDebug or someNewFlavorDebug to write Espresso tests
The answer from official documentation:
By default, all tests run against the debug build type. You can change
this to another build type by using the testBuildType property in your
module-level build.gradle file. For example, if you want to run your
tests against your "staging" build type, edit the file as shown in the
following snippet.
android {
...
testBuildType "staging" }
I am looking for a way to skip tests from one of the projects in a multi-build project. I don't want to use gradle build -x test because then it will skip test for all sub - projects.
Root
Sub P1
build.gradle
Sub P2
build.gradle
Sub P3
build.gradle
build.gradle
settings.gradle
I want to skip tests only for "Sub P3"
Can i configure my project(Sub P3) build file to skip tests?
Due to official user guide, there are 3 ways to skip some task in gradle.
The first 2, are: using predicate and exception throwing. Predicates are resolved during the configuration phase and may not pass to your requirements. StopExecutionExeptionthrowing could be added to the doFirst of every test and be throwed according to some condition. Bit that seems to be not very clear, because you have to modify both root script to set the condition and subroject sripts test tasks.
And the 3rd one is - disabling the tasks. Every task, has a enabled property (default is true), which is preventing task execution, if it was set to false. Only thing you have to do is to set this property for test task in your subproject. This can be done in sub projects buil script root, as:
test.enabled = false
This will work, if you didn't specify custom test tasks, if you did, you can disable all test by task type, as:
project(':subProject').tasks.withType(Test){
enabled = false
}
Previews 2 configurations must be included to the build script of the subproject, but since you have a root project, you can configure subprojecst from it's build script, via project() providing subproject's name:
project(':subProject').tasks.withType(Test){
enabled = false
}
For android there is no test task available in gradle
To skip unit tests in android you have to do this
android {
.
.
.
testOptions {
unitTests.all {
enabled false
}
}
}
I am having problem to find documentation how could I solve that case.
I am capable of launching small/medium/large tests with:
./gradlew spoonSmall
./gradlew spoonMedium
./gradlew spoonLarge
Or launching specific tests with usage of this setup:
spoon {
(...)
if (project.hasProperty('spoonClassName')) {
className = project.spoonClassName
if (project.hasProperty('spoonMethodName')) {
methodName = project.spoonMethodName
}
}
}
I can launch specific file:
./gradlew spoon -PspoonClassName=com.package.tests.MyTest;
What I am interested in is a possibility to launch all tests located in:
./gradlew spoon -PspoonClassName=com.package.tests
package. Either method is fine. Some parameter to bash console or maybe way to create my own annotation and launch by something like ./gradlew spoonMyTests.
I am grateful for suggestions/help.
From the official docs:
There are numerous ways to run a specific test, or set of tests. You
can use the Spoon --size, --class-name or --method-name options, or
you can use the --e option to pass arguments to the instrumentation
runner, e.g.
--e package=com.mypackage.unit_tests
The following command should work when executing Spoon directly from command line (not from the gradle task)
java -jar spoon-runner-1.1.9-jar-with-dependencies.jar \
--apk ExampleApp-debug.apk \
--test-apk ExampleApp-debug-androidTest-unaligned.apk \
--e package=com.package.tests
You need to find a way to pass this extra param to the Spoon gradle plugin.
UPDATE
From the official doc of Spoon Gradle plugin:
Custom instrumentation arguments
Use the instrumentationArgs property on spoon extension to pass custom
parameters to your tests:
spoon { instrumentationArgs = ["foo=bar", "name=value"] }
In your case, this should look like the following:
spoon {
instrumentationArgs = ["package=com.package.tests"]
}
Code coverage report not generated when Test case failed in android studio using Jacoco plugin.How to skip failed test case and generate code coverage report.
Try adding this flag when running your test
-Djacoco.haltonfailure=false
Use the following code in Build.gradle(Module:app):
android {
testOptions {
unitTests.all {
setIgnoreFailures(true)
}
}
buildTypes {
debug {
testCoverageEnabled true
}
}
}
If you just need to get the report you can add the #Ignore above the tests in order to temporarily skip them.
When you take care of the reason these tests fail then you just remove the annotation.
This annotation will not run any of the marked tests, you can use it either at class file or at the method/test.
I'm using the robolectric-gradle-plugin for robolectric unit tests. I don't want to fail a build on failed tests. Is there a way in DSL or a property not to fail a test on the build similar to -DtestFailureIgnore=true on the Surefire Maven plugin?
I've tried:
robolectric {
ignoreFailures = true
}
and
robolectric {
ignoreFailure = true
}
and -DignoreFailure=true on the command line.
I can't seem to find any documentation of how to do this, or any reference to ignoring tests in the source code.
answering very old question, so that it might help others who bump into here
testOptions {
unitTests.all {
setIgnoreFailures(true)
}
}
I would suggest not to continue building an APK if there are any failing tests. But if you want to build an APK without testing the only way right now is to use gradle build -x test[1]. This will run build and not run any tests.
[1]http://www.gradle.org/docs/current/userguide/userguide_single.html#sec:excluding_tasks_from_the_command_line
try without '='
robolectric {
ignoreFailures true
}