4
내가 Robolectric 2.2 간단한 JUnit 테스트를 실행하려고하지만 ADT 패키지 (22) 오류 사용하여 다음 얻고있다 :java.lang.ClassNotFoundException가 : android.R
이java.lang.NoClassDefFoundError: android/R
at org.robolectric.bytecode.Setup.<clinit>(Setup.java:40)
at org.robolectric.RobolectricTestRunner.createSetup(RobolectricTestRunner.java:137)
at org.robolectric.RobolectricTestRunner.createSdkEnvironment(RobolectricTestRunner.java:115)
at org.robolectric.RobolectricTestRunner$3.create(RobolectricTestRunner.java:278)
at org.robolectric.EnvHolder.getSdkEnvironment(EnvHolder.java:21)
at org.robolectric.RobolectricTestRunner.getEnvironment(RobolectricTestRunner.java:276)
at org.robolectric.RobolectricTestRunner.access$100(RobolectricTestRunner.java:57)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:190)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: android.R
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 24 more
이 나에게주는 코드는 오류가 다음을 :
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import com.mycomp.myapp.R;
@RunWith(RobolectricTestRunner.class)
public class ListToWatchActivityTest {
@Test
public void shouldHaveApplicationName() throws Exception {
String appName = new ListToWatchActivity().getResources().getString(R.string.app_name);
assertThat(appName, equalTo("MyApp"));
}
}
왜이 오류가 발생하는지 이해할 수 있습니까?
감사합니다.
정말로이 방법으로 활동의 새 인스턴스를 만들어야합니까? 또한 앱 패키지 이름과 "MyApp"를 항상 비교하고 싶지는 않다고 생각합니다. –
누락 된 수입으로 인한 것일 수 있습니다. ctrl + shft + o, 그런 다음 정리하고 실행하십시오. 코드 –
어떻게 junit을 운영하고 있습니까? 메이븐? 개미? – sheidaei