在 Android 1.6 上运行 jUnit 测试时出现VerifyError
以下是我尝试在 Android 1.6 上运行的内容:
package com.healthlogger.test;
public class AllTests extends TestSuite
{
public static Test suite()
{
return new TestSuiteBuilder(AllTests.class).includeAllPackagesUnderHere().build();
}
}
并且:
package com.healthlogger.test;
public class RecordTest extends AndroidTestCase
{
/**
* Ensures that the constructor will not take a null data tag.
*/
@Test(expected=AssertionFailedError.class)
public void testNullDataTagInConstructor()
{
Record r = new Record(null, Calendar.getInstance(), "Data");
fail("Failed to catch null data tag.");
}
}
主要项目是 HealthLogger。这些是从单独的测试项目(HealthLoggerTest)运行的。 HealthLogger 和 jUnit4 位于 HealthLoggerTest 的构建路径中。 jUnit4 也在 HealthLogger 的构建路径中。 “Record”类位于 com.healthlogger 中。
注释掉“@Test...”和“Record r...”行可以运行此测试。当它们被取消注释时,我得到一个VerifyError异常。我被这个严重阻碍了;为什么会发生这种情况?
编辑:崩溃后来自 logcat 的一些信息:
E/AndroidRuntime( 3723): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 3723): java.lang.VerifyError: com.healthlogger.test.RecordTest E/AndroidRuntime( 3723): at java.lang.Class.getDeclaredConstructors(Native Method)
E/AndroidRuntime( 3723): at java.lang.Class.getConstructors(Class.java:507) E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping$TestCasePredicate.hasValidConstructor(TestGrouping.java:226)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java:215)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java:211)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping.select(TestGrouping.java:170) E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping.selectTestClasses(TestGrouping.java:160)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:154)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:115)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:103)
E/AndroidRuntime( 3723): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:321)
E/AndroidRuntime( 3723): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3848)
E/AndroidRuntime( 3723): at android.app.ActivityThread.access$2800(ActivityThread.java:116) E/AndroidRuntime( 3723): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
E/AndroidRuntime( 3723): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3723): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 3723): at android.app.ActivityThread.main(ActivityThread.java:4203)
E/AndroidRuntime( 3723): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3723): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 3723): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 3723): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) E/AndroidRuntime( 3723): at dalvik.system.NativeStart.main(Native Method)
Here's what I'm trying to run on Android 1.6:
package com.healthlogger.test;
public class AllTests extends TestSuite
{
public static Test suite()
{
return new TestSuiteBuilder(AllTests.class).includeAllPackagesUnderHere().build();
}
}
and:
package com.healthlogger.test;
public class RecordTest extends AndroidTestCase
{
/**
* Ensures that the constructor will not take a null data tag.
*/
@Test(expected=AssertionFailedError.class)
public void testNullDataTagInConstructor()
{
Record r = new Record(null, Calendar.getInstance(), "Data");
fail("Failed to catch null data tag.");
}
}
The main project is HealthLogger. These are run from a separate test project (HealthLoggerTest). HealthLogger and jUnit4 are in HealthLoggerTest's build path. jUnit4 is also in HealthLogger's build path. The class "Record" is located in com.healthlogger.
Commenting out the "@Test..." and "Record r..." lines allows this test to run. When they are uncommented, I get a VerifyError exception. I am severely blocked by this; why is it happening?
EDIT: some info from logcat after the crash:
E/AndroidRuntime( 3723): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 3723): java.lang.VerifyError: com.healthlogger.test.RecordTest E/AndroidRuntime( 3723): at java.lang.Class.getDeclaredConstructors(Native Method)
E/AndroidRuntime( 3723): at java.lang.Class.getConstructors(Class.java:507) E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping$TestCasePredicate.hasValidConstructor(TestGrouping.java:226)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java:215)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java:211)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping.select(TestGrouping.java:170) E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping.selectTestClasses(TestGrouping.java:160)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:154)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:115)
E/AndroidRuntime( 3723): at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:103)
E/AndroidRuntime( 3723): at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:321)
E/AndroidRuntime( 3723): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3848)
E/AndroidRuntime( 3723): at android.app.ActivityThread.access$2800(ActivityThread.java:116) E/AndroidRuntime( 3723): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
E/AndroidRuntime( 3723): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3723): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 3723): at android.app.ActivityThread.main(ActivityThread.java:4203)
E/AndroidRuntime( 3723): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3723): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 3723): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 3723): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) E/AndroidRuntime( 3723): at dalvik.system.NativeStart.main(Native Method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您忘记导出测试项目的所有依赖项时,可能会发生这种情况。
在 Eclipse 中,转到项目(主项目和测试项目)的 Java Build Path 属性。转到“组织/导出”选项卡,并确保检查所有依赖项(选择全部,可能列出的任何 JRE 或类路径容器除外)。
This can occur when you forget to export all dependencies for a test project.
In Eclipse, go to the Java Build Path properties for your projects (both the main project and the test project). Go to the Organize/Export tab and make sure you check all dependencies (select all, except for any JRE or Classpath Container that might be listed).