Eclipse的+安卓+ JUnit测试参考android.os类=的NoClassDefFoundError [英] Eclipse + Android + JUnit test references android.os class = NoClassDefFoundError
问题描述
我有一个扩展android.os.CountDownTimer自定义定时器。我在测试项目(标准Android / Eclipse项目配置),测试自定义定时测试。当我运行这个测试,我得到:
I have a custom timer that extends android.os.CountDownTimer. I have a test in the test project (standard Android/Eclipse project config) that tests the custom Timer. When I run this test, I get:
java.lang.NoClassDefFoundError的:安卓/ OS / CountDownTimer
 在java.lang.ClassLoader.defineClass1(本机方法)
 在需要java.lang.ClassLoader.defineClass(ClassLoader.java:698)
java.lang.NoClassDefFoundError: android/os/CountDownTimer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:698)
您的想法。我无法运行code,它引用的Android code code在JUnit测试?
You get the idea. Can I not run code that references android code code in junit test?
推荐答案
您不能这样做,因为这是不可能的使用JUnit测试Android的资源没有进一步的说明。你必须首先仪项目。这个教程和下面的介绍了此过程非常好:
You can't do that because it isn't possible to test Android's resources with JUnit without further instructions. You have to instrument your project first. This tutorials and the following describes this procedure very well:
的http://mylifewithandroid.blogspot.com/2008/11/controlling-instrumentation.html
http://mylifewithandroid.blogspot.com/2008/11/junit-in -android.html
下面是另一个测试项目的解释code snipplet: http://marakana.com/tutorials/android/junit-test-example.html
Here is an explained code snipplet of another test project: http://marakana.com/tutorials/android/junit-test-example.html
在这里,你可以找到堆栈溢出的答案: <一href="http://stackoverflow.com/questions/522312/best-practices-for-unit-testing-android-apps">http://stackoverflow.com/questions/522312/best-practices-for-unit-testing-android-apps
And here you can find the answer on Stack Overflow: http://stackoverflow.com/questions/522312/best-practices-for-unit-testing-android-apps
这篇关于Eclipse的+安卓+ JUnit测试参考android.os类=的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!