我試圖運行我的soundkeeper
類,它不是一個活動,但它需要一個上下文,我不確定如何爲它提供一個。之前讓我很新的做單元測試,我沒有做任何的單元測試,這是我對測試類對上下文運行jUnit測試
public class SoundKeeperTest {
SoundKeeper sounds;
Context mContext;
@Before
public void setUp() throws Exception {
sounds = new SoundKeeper();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testAddSound() {
sounds.initSounds(mContext);
}
@Test
public void testPlaySound() {
fail("Not yet implemented");
}
}
當我嘗試從InstrumentationTestCase
獲取上下文方法的代碼,我收到以下錯誤
java.lang.NoClassDefFoundError: android/test/InstrumentationTestCase
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
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.test.InstrumentationTestCase
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 18 more
謝謝您的回覆。這些文件是我在發佈之前首先要檢查的文件,但沒有真正指導或解釋實施這種情況。我真的不明白髮生了什麼,我正在尋找一個實際的例子,所以我可以按照它並適用於我的例子。 – kabuto178 2013-05-11 18:07:28