How to run unit test on a android module?
Asked Answered
U

2

10

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?

Ullage answered 20/10, 2016 at 14:56 Comment(1)
Have you tried this: #24951921Roofdeck
R
1

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

Repatriate answered 20/10, 2016 at 15:1 Comment(2)
Compatible with robolectric?Ullage
But TestSuites should be in the same module it is testing.Dowson
C
1

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

Cha answered 16/1, 2017 at 21:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.