Java JUnit - 初始化错误中的异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26540438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JUnit - Exception In Initializer Error
提问by james
I'm trying to test a class with a static methods and I'm having an error in this line:
我正在尝试使用静态方法测试一个类,但在这一行中出现错误:
FormReferenceDataPopulator target = new FormReferenceDataPopulator();
and here's the failure trace:
这是故障跟踪:
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.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.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access##代码##0(ParentRunner.java:50)
at org.junit.runners.ParentRunner.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
回答by Saifuddin Merchant
There are couple of clues in the stack trace the point what the error is
堆栈中有几条线索可以追踪错误是什么
a) ExceptionInInitializerError --> FormReferenceDataPopulatorTest. This indicates that the error happened during the construction of this object. The ExceptionInInitializerError specifically point to the fact that the exception occurred during static initialization block or variable
a) ExceptionInInitializerError --> FormReferenceDataPopulatorTest。这表明在构建此对象的过程中发生了错误。ExceptionInInitializerError 专门指出异常发生在静态初始化块或变量期间
ExceptionInInitializerErrorSignals that an unexpected exception has occurred in a static initializer. An ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.
ExceptionInInitializerError表示静态初始化程序中发生了意外异常。抛出 ExceptionInInitializerError 以指示在评估静态初始值设定项或静态变量的初始值设定项期间发生异常。
b) Like Robby has pointed out in his comment Caused by: java.lang.RuntimeException: Could not locate bean of class [au.necdl.pexa.service.address.CountryService] shows what the error exact is.
b) 就像 Robby 在他的评论中指出的那样 引起:java.lang.RuntimeException:无法定位类 [au.necdl.pexa.service.address.CountryService] 的 bean 显示了错误的确切含义。