我有一个类ClassA,它从org.apache.struts.actions.DispatchAction扩展了DispatchAction类。我已经为ClassA编写了JUnit代码覆盖测试,但是每当我尝试运行测试用例时,我总是得到这些错误,但是如果我从ClassA中删除extends DispatchAction
,测试将正常运行,没有任何错误,但是显然我的应用程序将无法运行ClassA
public class ClassA extends DispatchAction {
//some methods and other code
}
测试类别A
@RunWith(Junit4.class)
public class TestClassA {
@InjectMocks
ClassA objA;
/* mock some objects here */
@Before
public void setUp()
{
MockitoAnnotations.openMocks(this);
}
@Test
public void methodToTest()
{
//Coverage code
objA.methodA();
}
}
这是我运行这个测试用例时得到的堆栈跟踪(当我在类ClassA中保留“extends DispatchAction”时)
java.lang.ExceptionInInitializerError at
java.lang.J9VMInternals.ensureError(J9VMInternals.java:148) at
java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:137) at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:83) at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57) at
java.lang.reflect.Constructor.newInstance(Constructor.java:437) at
org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217) at
org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at
org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263) at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at
org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at
org.junit.runners.ParentRunner.run(ParentRunner.java:363) at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41) at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541) at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463) at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.NullPointerException at
org.apache.struts.util.MessageResources.getMessageResources(MessageResources.java:577) at
org.apache.struts.actions.DispatchAction.<clinit>(DispatchAction.java:153) ... 22 more
现在,如果我从类ClassA中删除“extends DispatchAction”,它将运行并覆盖测试用例中的预期行,而不会出现任何问题,但我的应用程序将无法按预期工作。
我试着搜索如何解决所有这些错误,但我找不到任何可能有帮助的东西。
1条答案
按热度按时间dzjeubhm1#
已通过添加先前丢失的最新j2ee jar解决此问题。