4

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.

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

3 Comments

This has ended up being my final solution. I just don't understand why the Junit runner wouldn't be able to pick it up. But whatever works I guess.
I suppose com.dddforandroid.api is your custom package here, with the tests?
But isnt that an instrumented test then? I mean the whole idea about unit tests is to not build a whole app, install it on a device and run it there. I understood intrumented tests do exactly this (opposite to unit tests). What am I missing?
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.