【问题标题】:Joda Time - Cannot run JUnit tests in Eclipse or IntelliJJoda Time - 无法在 Eclipse 或 IntelliJ 中运行 JUnit 测试
【发布时间】:2017-11-21 23:13:44
【问题描述】:

我在本地克隆了 joda-time GitHub 存储库,将它作为 Eclipse 和 IntelliJ Idea 中的 Maven 项目导入,它在两个 IDE 中构建得非常好。但是当尝试运行 JUnit 测试时,它在任何一个 IDE 中都不起作用,我看不出问题出在哪里。

我知道我需要创建一个额外的文件夹

src\tz-data\org\joda\time\tz\data

把这两个文件放在那里

CET
ZoneInfoMap

我已经做到了。

JUnit 测试仍然没有运行,有趣的是我在 Eclipse 下得到了完全不同的错误:

java.lang.ExceptionInInitializerError
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:100)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:51)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalArgumentException: The datetime zone id 'Europe/Paris' is not recognised
    at org.joda.time.DateTimeZone.forID(DateTimeZone.java:234)
    at org.joda.time.TestLocalDate_Basics.<clinit>(TestLocalDate_Basics.java:50)
    ... 10 more

在 IntelliJ Idea 下:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.joda.time.TestAbstractPartial
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at junit.framework.TestSuite.createTest(TestSuite.java:58)
    at junit.framework.TestSuite.addTestMethod(TestSuite.java:280)
    at junit.framework.TestSuite.<init>(TestSuite.java:140)
    at com.intellij.junit3.TestRunnerUtil.createClassOrMethodSuite(TestRunnerUtil.java:147)
    at com.intellij.junit3.TestAllInPackage2.<init>(TestAllInPackage2.java:32)
    at com.intellij.junit3.TestRunnerUtil.getTestSuite(TestRunnerUtil.java:78)
    at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:43)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

非常感谢任何有关如何解决此问题的提示。

【问题讨论】:

  • 查看他们的 pom.xml 它依赖于 exec 插件来调用 org.joda.time.tz.ZoneInfoCompiler 并生成一些文件。在 intellij 中,我进入了 maven 栏并运行了生命周期的编译步骤,之后单元测试开始工作。
  • 谢谢罗比,你是对的。我终于想通了... :)

标签: eclipse intellij-idea junit jodatime


【解决方案1】:

我是 maven 新手,事实证明问题出在我尝试运行测试的方式上。

正如 roby 所说,我应该使用 IntelliJ 中的 maven 栏来运行正确的 maven 目标(同样,我应该使用 Run As.. 和 Eclipse 中的正确 maven 目标),而我只是想运行通过使用 IDE 进行测试,即右键单击项目并“运行所有测试”,这是可以理解的,因为它没有使用正确的配置。

【讨论】:

    猜你喜欢
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多