How to run unit test on an Android module?

I have an Android project that has several library modules, and I'm trying to test a specific package containing all the modules.

I tried this command:

./gradlew -Dtest.single=com.moduleone* testProductionDebug 

And this will not work: it does not run tests inside this module, but instead executes all unit tests in the class of the main project package.

How to check only one module?

+8
android android-gradle junit gradle robolectric-gradle-plugin
source share
2 answers

You can use test suits: https://developer.android.com/reference/junit/framework/TestSuite.html . The costume definition contains the test classes you need.

+2
source share

Assuming you are trying to complete the gradle task for a single module, and not for the entire project, you can specify the module name before the colon separated task ( module_name:task )

For your question, it will look something like this: ./gradlew -Dtest.single=com.moduleone* your_library_module:testProductionDebug

This is a simple example if you have a simple project setup. You can also find further reading of this document in gradle docs for multi- project builds.

+1
source share

All Articles