JUnit NoClassDefFoundError 与 JAR 文件
我开发了一个 Android 应用程序,现在正在为其创建单元测试。 我创建了第二个项目(后缀为“.test”作为项目名称)并选择原始项目作为目标。
我的原始项目包含一些外部 JAR 文件。
如果不在我的测试项目的构建路径中引用这些 JAR 文件,我就无法访问测试中的所有方法。 例如,我收到此错误:
The type com.j256.ormlite.android.apptools.OrmLiteBaseService cannot be resolved. It is indirectly referenced from required .class files
测试确实可以正常工作(当不访问这些方法时)。
如果我在测试项目的构建路径中包含所需的 JAR 文件,则会收到此错误:
05-16 15:59:03.732: INFO/TestRunner(1222): java.lang.NoClassDefFoundError: sw6.visualschedule.persistence.DatabaseHelper
05-16 15:59:03.732: INFO/TestRunner(1222): at sw6.visualschedule.test.ScheduleActivityTest.setUp(ScheduleActivityTest.java:22)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestCase.runBare(TestCase.java:125)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestResult$1.protect(TestResult.java:106)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestResult.runProtected(TestResult.java:124)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestResult.run(TestResult.java:109)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestCase.run(TestCase.java:118)
05-16 15:59:03.732: INFO/TestRunner(1222): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
05-16 15:59:03.732: INFO/TestRunner(1222): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
05-16 15:59:03.732: INFO/TestRunner(1222): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
05-16 15:59:03.732: INFO/TestRunner(1222): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
如何解决 NoClassDefFoundError? 我真的很困惑,因为它引用了我的项目中的一个类,并且当外部 JAR 文件不包含在构建路径中时它可以工作。
我在 OSX 上使用 Eclipse,如果这有任何影响的话。
I have developed an Android application which I am now creating unit tests for.
I have created a second project (suffixed with ".test" as the projectname) and selected the original project as the target.
My original project includes a few external JAR files.
I cannot access all methods from my tests without referencing these JAR files in my test project's build path as well.
As an example, I get this error:
The type com.j256.ormlite.android.apptools.OrmLiteBaseService cannot be resolved. It is indirectly referenced from required .class files
Tests do work correctly though (when not accessing those methods).
If I include the required JAR files in the test project's build path, I get this error however:
05-16 15:59:03.732: INFO/TestRunner(1222): java.lang.NoClassDefFoundError: sw6.visualschedule.persistence.DatabaseHelper
05-16 15:59:03.732: INFO/TestRunner(1222): at sw6.visualschedule.test.ScheduleActivityTest.setUp(ScheduleActivityTest.java:22)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestCase.runBare(TestCase.java:125)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestResult$1.protect(TestResult.java:106)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestResult.runProtected(TestResult.java:124)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestResult.run(TestResult.java:109)
05-16 15:59:03.732: INFO/TestRunner(1222): at junit.framework.TestCase.run(TestCase.java:118)
05-16 15:59:03.732: INFO/TestRunner(1222): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
05-16 15:59:03.732: INFO/TestRunner(1222): at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
05-16 15:59:03.732: INFO/TestRunner(1222): at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
05-16 15:59:03.732: INFO/TestRunner(1222): at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
How can I resolve the NoClassDefFoundError?
I am really confused since it refers to a class inside my project, and it works when the external JAR file isn't included in the build path.
Im using Eclipse on OSX, if that has any influence.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将这些库导出到测试项目,但在测试项目中引用它们
Export those libs to test project, but refer them in the test project