我正在使用Android工作室运行JUnit测试,这很棒。
为了做到这一点,我不得不进行一些争论并将以下内容添加到VM选项中,因为将junit 4.12添加到 Application 的 Dependencies 中项目结构无效。
我的问题是:为什么,我做错了什么?
-ea -classpath "C:\Users\obfuscated\.gradle\caches\modules-2\files-2.1\junit\junit\4.12\2973d150c0dc1fefe998f834810d68f278ea58ec\junit-4.12.jar;D:\Program Files\Android\Android Studio\lib\idea_rt.jar;D:\Program Files\Android\Android Studio\plugins\junit\lib\junit-rt.jar;D:\Android\sdk\platforms\android-21\android.jar;D:\Android\sdk\platforms\android-21\data\res;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\classes\test\debug;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\classes\debug;C:\Users\obfuscated\.gradle\caches\modules-2\files-2.1\org.objenesis\objenesis\1.0\9b473564e792c2bdf1449da1f0b1b5bff9805704\objenesis-1.0.jar;C:\Users\obfuscated\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.3\libs\internal_impl-21.0.3.jar;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.3\classes.jar;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.3\res;D:\Android\sdk\extras\android\m2repository\com\android\support\support-annotations\21.0.3\support-annotations-21.0.3.jar;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\exploded-aar\com.android.support\support-v13\21.0.2\libs\internal_impl-21.0.2.jar;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\exploded-aar\com.android.support\support-v13\21.0.2\classes.jar;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\exploded-aar\com.android.support\support-v13\21.0.2\res;C:\Users\obfuscated\.gradle\caches\modules-2\files-2.1\org.mockito\mockito-core\1.9.5\c3264abeea62c4d2f367e21484fbb40c7e256393\mockito-core-1.9.5.jar;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\exploded-aar\com.android.support\cardview-v7\21.0.2\res;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\exploded-aar\com.android.support\cardview-v7\21.0.2\classes.jar;D:\Android\projets\AndroidStudioProjects\ElevationDrag\Application\build\intermediates\mockable-android-21.jar"
如果我按照here给出的说明,我发现自己有以下错误:
!!! JUnit version 3.8 or later expected:
java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.junitVersionChecks(JUnitStarter.java:190)
at com.intellij.rt.execution.junit.JUnitStarter.canWorkWithJUnitVersion(JUnitStarter.java:173)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code -3
答案 0 :(得分:0)
Android类必须在设备或模拟器中运行。如果不是,你需要一些方法来模拟android.jar
请看一下: http://tools.android.com/tech-docs/unit-testing-support 要么 http://robolectric.org/