在java

时间:2016-05-16 05:29:34

标签: java junit

我在运行测试类时遇到以下异常。  该类尝试初始化是完整路径可用,但在运行时给我错误。任何人都可以建议我做错了什么。提前致谢。

        java.lang.NoClassDefFoundError: Could not initialize class
        at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
            at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
            at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:111)
            at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:51)
            at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:100)
            at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:58)
            at org.powermock.api.mockito.PowerMockito.mock(PowerMockito.java:138)
        at com.idit.contact.server.manager.XXXTests_FindContactById.additionalDataNotSpecified_ShouldCallGetFullContactVO
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
            at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:312)
            at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:88)
            at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:96)
            at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:296)
            at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:284)
            at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:86)
            at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
            at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:209)
            at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:148)
            at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
            at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:33)
            at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:45)
            at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
            at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:102)
            at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
            at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:42)
            at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
            at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
            at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
            at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)





     My Test Class is:

        @SuppressWarnings("deprecation")
        @RunWith(PowerMockRunner.class)
        @PrepareForTest({XXX.class, SomeExceptionHandler.class})
        @PowerMockIgnore({"com.abc.XXX",
                "org.apache.commons.logging.*",
                "org.apache.log4j.*"})

        public class XXXTests_FindContactById {

        @Test
            public void additionalDataNotSpecified_ABC() {

                XXX cdm = PowerMockito.mock(XXX.class);

            }
        }

1 个答案:

答案 0 :(得分:-1)

NoClassDefinitionFoundError在您要使用的类在运行时不可用时发生,即使它在编译时可用。请检查您的类路径以了解.class文件是否存在。请研究此链接http://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html < / p>