JUnit NoClassDefFoundError with JAR file
I have developed an开发者_如何学Go 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.
Export those libs to test project, but refer them in the test project
精彩评论