我试图运行单元测试与Robolectric Android Studio中。我几乎没有 - 我看到:
I'm trying to run unit tests with Robolectric in Android Studio. I'm almost there - I see:
!!! 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:185)
...
我也看到在类路径中的所有需要的依赖。要解决这个错误我需要把junit4依赖Android SDK中的依赖了。不幸的是我没有看到的项目结构的部分模块,我不知道如何编辑的 IML 的文件归档此。
I see also all required dependencies in class path. To fix this error I need to put junit4 dependency before android sdk dependency. Unfortunately I don't see module in Project Structure section and I don't know how to edit iml file to archive this.
下面是从我的项目结构截图:
Here is screenshot from my project structure:
我的文件的gradle:
My gradle file:
sourceSets {
testLocal {
java.srcDir file('src/test/java')
resources.srcDir file('src/test/resources')
}
}
dependencies {
// compatibility
compile 'android.compatibility:android-support:v4-r13'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
testLocalCompile 'junit:junit:4.11'
testLocalCompile 'org.robolectric:robolectric:2.2'
testLocalCompile 'org.easytesting:fest-assert-core:2.0M10'
}
android {
buildToolsVersion "17"
compileSdkVersion 18
productFlavors {
testLocal{
}
}
}
和我选的 testLocal 的风味为。
使用的Android 0.5.7工作室,可以通过项目结构对话框,或只是把行 androidTestCompileJUnit来保持相关性秩序:JUnit的:4 +
上方FO 依赖
部分
With Android Studio 0.5.7 it is possible to keep order of dependencies through "Project Structure" dialog or just putting line androidTestCompile 'junit:junit:4.+'
at the top fo dependencies
section.
然而,这是不够的,运行Android Studio中测试。新的错误是:
However this is not enough to run tests inside Android Studio. The new error is:
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
因此,它看起来像我的JUnit依赖不会传播到JUnit的运行。我试图让它进一步的工作。
So it looks like my junit dependency is not propagated to junit run. I'm trying to make it working further