Running Android Junit tests from command line

2019-02-14 23:57发布

问题:

I want to be able to run Junit tests from the command line, but when I run this command

java -cp /usr/share/java/junit.jar org.junit.runner.JUnitCore [test class name]

All I get back is

OK (0 tests)

Does it have something to do with it being an Android project? I've run that command before and haven't had much issue.

回答1:

I just managed to run JUnit tests from command line, but using an adb shell.

The command was

./adb shell am instrument -w com.dddforandroid.api/android.test.InstrumentationTestRunner

More details here.



回答2:

Template:

adb shell am instrument -w <YOUR_PACKGE_NAME>.test/android.support.test.runner.AndroidJUnitRunner

Example:

adb shell am instrument -w com.example.android.testing.blueprint.flavor2.test/android.support.test.runner.AndroidJUnitRunner

Details on Google's github page: Android Testing Blueprint