Jono
Jono

Reputation: 18108

How to run unit test on a android module?

I have a android project that has multiple library modules and I am trying to test a specific package that contains all modules.

I tried this command:

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

And it does not work: it doesn't execute the tests inside this module, but instead executes all the unit tests in the main project package class.

How do I test just the one module?

Upvotes: 10

Views: 2206

Answers (2)

Brad
Brad

Reputation: 513

Assuming you're trying to execute a gradle task against a single module rather than the entire project, you can supply the name of the module in front of the task separated by a colon (module_name:task)

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

This is a simple example, assuming you have a simple project setup. You can also find further reading on this in the gradle docs for executing a multi-project build

Upvotes: 1

Alex Shutov
Alex Shutov

Reputation: 3282

You can use test suits: https://developer.android.com/reference/junit/framework/TestSuite.html . Definition of a suit contains classes of tests you need

Upvotes: 1

Related Questions