Eclipse + Android + JUnit测试引用android.os class = NoClassDefFoundError [英] Eclipse + Android + JUnit test references android.os class = NoClassDefFoundError
问题描述
java.lang.NoClassDefFoundError:android / os / CountDownTimer
  ;在java.lang.ClassLoader.defineClass1(本机方法)
在java.lang.ClassLoader.defineClass(ClassLoader.java:698)
你会得到想法。我可以不运行引用android代码的代码在junit测试?
你不能这样做,因为它不是可以使用JUnit测试Android的资源,无需进一步的指示。你必须首先调整你的项目。本教程和以下内容很好地描述了这个过程:
http://mylifewithandroid.blogspot.com/2008/11/controlling-instrumentation.html
http://mylifewithandroid.blogspot.com/2008/11/junit-in-android.html
这是另一个测试项目的解释代码snipplet:
http://marakana.com/tutorials/android/junit-test-example.html
在这里你可以在Stack Overflow上找到答案:
https:// stackoverflow。 com / questions / 522312 / for-unit-testing-android-apps的最佳做法
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: android/os/CountDownTimer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:698)
You get the idea. Can I not run code that references android code code in junit test?
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
Here is an explained code snipplet of another test project: http://marakana.com/tutorials/android/junit-test-example.html
And here you can find the answer on Stack Overflow: https://stackoverflow.com/questions/522312/best-practices-for-unit-testing-android-apps
这篇关于Eclipse + Android + JUnit测试引用android.os class = NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!