【问题标题】:JUnit - Exception In Initializer ErrorJUnit - 初始化程序错误中的异常
【发布时间】:2014-10-24 02:09:30
【问题描述】:

我正在尝试使用静态方法测试一个类,但在这一行出现错误:

FormReferenceDataPopulator target = new FormReferenceDataPopulator();

这是失败的痕迹:

java.lang.ExceptionInInitializerError
  at au.necdl.pexa.web.document.form.FormReferenceDataPopulatorTest.<init>(FormReferenceDataPopulatorTest.java:15)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
  at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
  at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
  at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.RuntimeException: Could not locate bean of class [au.necdl.pexa.service.address.CountryService]
  at au.necdl.pexa.core.PexaContextAware.getBean(PexaContextAware.java:65)
  at au.necdl.pexa.web.document.form.FormReferenceDataPopulator.<clinit>(FormReferenceDataPopulator.java:29)    ... 23 more

【问题讨论】:

  • 您的堆栈跟踪的相关部分:无法找到 [au.necdl.pexa.service.address.CountryService] 类的 bean

标签: java junit


【解决方案1】:

堆栈跟踪中有几个线索表明错误所在

a) ExceptionIninitializerError --> FormReferenceDataPopulatorTest。 这表明错误发生在该对象的构造过程中。 ExceptionIninitializerError 专门指向在静态初始化块或变量期间发生异常的事实

ExceptionIninitializerError 抛出 ExceptionIninitializerError 以指示在计算静态初始化程序或静态变量初始化程序期间发生异常。

b) 就像 Robby 在他的评论中指出的那样,Caused by: java.lang.RuntimeException: Could not locate bean of class [au.necdl.pexa.service.address.CountryService] 显示了错误的确切位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 2010-11-16
    • 1970-01-01
    • 2014-11-03
    • 2012-02-01
    相关资源
    最近更新 更多