continue jacoco code coverage report after fail test case - android

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.

Related

Gradle Espresso - Task connectedProductFlavorBuildTypeAndroidTest not found in root project

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" }

Add variable in gradle command

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.

How to get code coverage report for android instrumentation tests

How do I find the code coverage for instrumentation test case, the run tests with code coverage button is disabled.
Please help.
Before that you need to enable Coverage in gradle file at app level .
buildTypes {
debug
{
testCoverageEnabled = true
}
}
Once done you can run below command in Terminal
gradlew createDebugCoverageReport
You can check it at below path
YoutProjectName\app\build\reports\coverage\debug
and check index.html file in your browser.

'transformClassesWithMultidexlistForDebugAndroidTest' task fails when android.support.test.runner.AndroidJUnitRunner specified

I'm trying to run an espresso test on MultiDex app and am failing with the below error
Error:Execution failed for task > :transformClassesWithMultidexlistForDebugAndroidTest'.
java.io.IOException: The output jar is empty. Did you specify the proper > '-keep' options?
Here's the relevant section in my build.gradle
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
dexOptions {
jumboMode true
}
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
I do have a workaround which is to:
comment out 'testInstrumentationRunner' line
Build the test
Uncomment the line
Run the test
This seems to work, but I need to re-do this any time I'm changing my test code, which is a major pain.
Could fine similar error online, but nothing specific to my case...
I am building using Android studio
My reputation doesn't allow me to comment, so will write as an answer:
Exactly the same workaround works for me:
Commenting the string with 'testInstumentationRunner'
Building tests. There will be an exception that Instrumentation Runner is not found
Uncomment the string
Run the test
UPD: This solution worked for me, though the question there is about different problem:
Android Espresso not working with Multidex gives "No tests found"

How can I ignore test failures with the gradle robolectric plugin?

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
}

Categories

Resources