简体   繁体   English

带有JAR文件的JUnit NoClassDefFoundError

[英]JUnit NoClassDefFoundError with JAR file

I have developed an Android application which I am now creating unit tests for. 我已经开发了一个Android应用程序,现在正在为其创建单元测试。 I have created a second project (suffixed with ".test" as the projectname) and selected the original project as the target. 我创建了第二个项目(后缀为“ .test”作为项目名称),然后选择原始项目作为目标。

My original project includes a few external JAR files. 我的原始项目包括一些外部JAR文件。

I cannot access all methods from my tests without referencing these JAR files in my test project's build path as well. 如果无法在测试项目的构建路径中引用这些JAR文件,则无法访问测试中的所有方法。 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: 如果我在测试项目的构建路径中包含必需的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)

How can I resolve the NoClassDefFoundError? 如何解决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. 我真的很困惑,因为它引用了我项目中的一个类,并且当构建路径中不包含外部JAR文件时,它可以工作。

Im using Eclipse on OSX, if that has any influence. 我在OSX上使用Eclipse(如果有影响)。

将这些库导出到测试项目,但在测试项目中引用它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM