web-dev-qa-db-ja.com

java.lang.NoClassDefFoundError:クラスorg.mockito.internal.util.MockUtilを初期化できませんでした

Testng + powermock + springを使用してテストコードを実行したいのですが、jarバージョンは次のとおりです。

powermock = 1.6.2
powermock-module-testng = 1.6.2 
mockito = 1.10.19
testng = 6.8.7
spring = 4.1.1.RELEASE
JDK = 1.8.0

そして、次のような私のテストコードは、AutoBaseTestを拡張せず、通常どおり実行できます。AutoBaseTestには@ContextConfiguration(locations = {"/ test/resources/applicationContext-test.xml"})が含まれています。

    @PrepareForTest({test.class}) 


  public class mockTest extends AutoBaseTest {

    @ObjectFactory
    public IObjectFactory getObjectFactory() {

        return new PowerMockObjectFactory();
    }


    @Test
    public final void test() throws Exception  {
        ......
    }
    }

エラースタック:

`FAILED CONFIGURATION: @BeforeClass springTestContextBeforeTestClass
Java.lang.ExceptionInInitializerError
at org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter.(ConditionalStackTraceFilter.Java:17)
at org.mockito.exceptions.base.MockitoException.filterStackTrace(MockitoException.Java:41)
at org.mockito.exceptions.base.MockitoException.(MockitoException.Java:30)
at org.mockito.exceptions.misusing.MockitoConfigurationException.(MockitoConfigurationException.Java:18)
at org.mockito.internal.configuration.plugins.PluginLoader.loadImpl(PluginLoader.Java:66)
at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.Java:24)
at org.mockito.internal.configuration.plugins.PluginRegistry.(PluginRegistry.Java:12)
at org.mockito.internal.configuration.plugins.Plugins.(Plugins.Java:11)
at org.mockito.internal.util.MockUtil.(MockUtil.Java:24)
at org.mockito.internal.configuration.injection.scanner.MockScanner.(MockScanner.Java:22)
at org.mockito.internal.configuration.InjectingAnnotationEngine.injectMocks(InjectingAnnotationEngine.Java:96)
at org.powermock.api.mockito.internal.configuration.PowerMockitoInjectingAnnotationEngine.process(PowerMockitoInjectingAnnotationEngine.Java:35)
at org.powermock.api.extension.listener.AnnotationEnabler.injectSpiesAndInjectToSetters(AnnotationEnabler.Java:60)
at org.powermock.api.extension.listener.AnnotationEnabler.beforeTestMethod(AnnotationEnabler.Java:55)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.Java:1873)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.Java:663)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.Java:415)
at org.powermock.modules.testng.internal.PowerMockTestNGMethodHandler.injectMocksUsingAnnotationEnabler(PowerMockTestNGMethodHandler.Java:75)
at org.powermock.modules.testng.internal.PowerMockTestNGMethodHandler.invoke(PowerMockTestNGMethodHandler.Java:47)
at test.Java.com.sosoPay.servicetest.mockTest_$$jvstb5f_0.springTestContextBeforeTestClass(mockTest$$_jvstb5f_0.Java)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.Java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.Java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.Java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.Java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.Java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.Java:107)
at org.testng.TestRunner.privateRun(TestRunner.Java:767)
at org.testng.TestRunner.run(TestRunner.Java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.Java:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.Java:330)
at org.testng.SuiteRunner.privateRun(SuiteRunner.Java:291)
at org.testng.SuiteRunner.run(SuiteRunner.Java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.Java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.Java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.Java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.Java:1149)
at org.testng.TestNG.run(TestNG.Java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.Java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.Java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.Java:175)
Caused by: Java.lang.NullPointerException
at org.mockito.internal.configuration.plugins.Plugins.getStackTraceCleanerProvider(Plugins.Java:17)
at org.mockito.internal.exceptions.stacktrace.StackTraceFilter.(StackTraceFilter.Java:21)
... 48 more

FAILED CONFIGURATION: @AfterMethod springTestContextAfterTestMethod(public final void test.Java.com.sosoPay.servicetest.mockTest.test() throws Java.lang.Exception)
Java.lang.NoClassDefFoundError: Could not initialize class org.mockito.internal.util.MockUtil
at org.mockito.internal.configuration.injection.scanner.MockScanner.(MockScanner.Java:22)
at org.mockito.internal.configuration.InjectingAnnotationEngine.injectMocks(InjectingAnnotationEngine.Java:96)
at org.powermock.api.mockito.internal.configuration.PowerMockitoInjectingAnnotationEngine.process(PowerMockitoInjectingAnnotationEngine.Java:35)
at org.powermock.api.extension.listener.AnnotationEnabler.injectSpiesAndInjectToSetters(AnnotationEnabler.Java:60)
at org.powermock.api.extension.listener.AnnotationEnabler.beforeTestMethod(AnnotationEnabler.Java:55)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.Java:1873)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.Java:663)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.Java:415)
at org.powermock.modules.testng.internal.PowerMockTestNGMethodHandler.injectMocksUsingAnnotationEnabler(PowerMockTestNGMethodHandler.Java:75)
at org.powermock.modules.testng.internal.PowerMockTestNGMethodHandler.invoke(PowerMockTestNGMethodHandler.Java:47)
at test.Java.com.sosoPay.servicetest.mockTest_$$jvstb5f_0.springTestContextAfterTestMethod(mockTest$$_jvstb5f_0.Java)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.Java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.Java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.Java:213)
at org.testng.internal.Invoker.invokeMethod(Invoker.Java:786)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.Java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.Java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.Java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.Java:111)
at org.testng.TestRunner.privateRun(TestRunner.Java:767)
at org.testng.TestRunner.run(TestRunner.Java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.Java:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.Java:330)
at org.testng.SuiteRunner.privateRun(SuiteRunner.Java:291)
at org.testng.SuiteRunner.run(SuiteRunner.Java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.Java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.Java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.Java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.Java:1149)
at org.testng.TestNG.run(TestNG.Java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.Java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.Java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.Java:175)

FAILED CONFIGURATION: @AfterClass springTestContextAfterTestClass
Java.lang.NoClassDefFoundError: Could not initialize class org.mockito.internal.util.MockUtil
at org.mockito.internal.configuration.injection.scanner.MockScanner.(MockScanner.Java:22)`
6
chen

これは Mockitoの欠陥 コンテキストクラスローダーがPowerMockおよびMockitoのロードに使用されるものと異なる場合にプラグインをロードすることです。

Mockito 2で修正される可能性がありますが、コメントで述べたように

1.xの修正をバックポートするためのビルドインフラストラクチャがあるかどうかわからない

Mockito 1の場合、修正は配信できないため、PowerMockで修正し、修正は次のPowerMockリリースに含まれる予定です( PowerMock 1.6.5 )。

7