1
對於我的Android項目,我想測試純Java代碼。爲了實現這一點,我想使用JUnit。Android Junit - 「未找到類」
由於已知的bug:
!!! 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)
我安裝了正確的插件到Android Studio和補充:
classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
和
apply plugin: 'android-unit-test'
dependencies {
testCompile('junit:junit:4.11')
}
由於加入JUnit的應用的build.gradle我在src/androidTest/java/com.adamstyrc.mytrack.unit中寫了簡單的測試類:
package com.adamstyrc.mytrack.unit;
import junit.framework.TestCase;
public class SimpleTest extends TestCase {
public void testName() {
assertEquals(7, 6);
}
}
但我得到的是:
Class not found: "com.adamstyrc.mytrack.unit.SimpleTest"
爲什麼不可見?
check [this out](http://stackoverflow.com/questions/2422378/intellij-idea-with-junit-4-7-junit-version-3-8-or-later-expected) – Elltz