bash 从命令行运行 Android Junit 测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11144466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:33:05  来源:igfitidea点击:

Running Android Junit tests from command line

javaandroidbashcommand-linejunit

提问by ZacAttack

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

我希望能够从命令行运行 Junit 测试,但是当我运行此命令时

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.

它与它是一个Android项目有关系吗?我以前运行过该命令,但没有太大问题。

回答by andreea.sandu

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

我只是设法从命令行运行 JUnit 测试,但使用 adb shell。

The command was

命令是

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

More details here.

更多细节在这里

回答by 0x8BADF00D

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

Google 的 github 页面上的详细信息:Android 测试蓝图