简体   繁体   中英

How to exlude tests when generating coverage reports using Jacoco on Android with gradle

I want to run a single Gradle command which generates a coverage report as well as runs a specific set of tests, not every test in the package. In this instance, I want to generate the report on my instrumentation tests and not on my UI tests.

I have set up Jacoco so that I can run the Gradle command ./gradlew create<package-name>DebugAndroidTestCoverageReport to run all of my tests in the androidTest folder.

I've tried ./gradlew create<package-name>DebugAndroidTestCoverageReport --tests "com.myproject.test.*" to only run the tests located in the test package but this returns the error Unknown command-line option '--tests' .

Using the Gradle command test --tests "com.myproject.test.*" Works fine and runs the specified tests, but does not generate the coverage report.

Is there a way that I can have test filtering while still generating the coverage report?

After some searching I stumbled upon this question Android, Gradle. How start specific instrumented test method? which gave me the answer.

In order to filter out test cases by package you can use

./gradlew create<package-name>DebugAndroidTestCoverageReport -Pandroid.testInstrumentationRunnerArguments.package=com.example.test

This command will generate the coverage report only on the specified tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM