Eclipse + Android + JUnit测试引用android.os class = NoClassDefFoundError [英] Eclipse + Android + JUnit test references android.os class = NoClassDefFoundError

查看:112
本文介绍了Eclipse + Android + JUnit测试引用android.os class = NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的定时器来扩展android.os.CountDownTimer。我在测试项目(标准Android / Eclipse项目配置)中测试自定义Timer。当我运行这个测试,我得到:


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆