JUnit NoClassDefFoundError 与 JAR 文件

发布于 2024-11-07 08:47:53 字数 1833 浏览 4 评论 0原文

我开发了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑凤梨 2024-11-14 08:47:53

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

Export those libs to test project, but refer them in the test project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文