目前我测试了 springboot 2 的新版本。我按照提供的文档创建了一个 @controller 和相关的测试。但是当我运行测试时,我总是得到以下异常:
2018-04-30 21:02:49.536 WARN 13584 --- [ main] o.s.test.context.TestContextManager : Caught exception while invoking 'afterTestMethod' callback on TestExecutionListener [org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@1e81f160] for test method [public void com.example.demo.DemoApplicationTests.contextLoads()] and test instance [com.example.demo.DemoApplicationTests@1672fe87]
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker
at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:60) ~[mockito-core-2.15.0.jar:na]
at com.sun.proxy.$Proxy72.getHandler(Unknown Source) ~[na:na]
at org.mockito.internal.util.MockUtil.isMock(MockUtil.java:81) ~[mockito-core-2.15.0.jar:na]
at org.mockito.internal.util.DefaultMockingDetails.isMock(DefaultMockingDetails.java:35) ~[mockito-core-2.15.0.jar:na]
at org.springframework.boot.test.mock.mockito.MockReset.get(MockReset.java:106) ~[spring-boot-test-2.0.1.RELEASE.jar:2.0.1.RELEASE]
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:84) ~[spring-boot-test-2.0.1.RELEASE.jar:2.0.1.RELEASE]
Caused by: java.lang.NoClassDefFoundError: net/bytebuddy/dynamic/loading/ClassLoadingStrategy
at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.<init>(SubclassByteBuddyMockMaker.java:33) ~[mockito-core-2.15.0.jar:na]
at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.<init>(ByteBuddyMockMaker.java:21) ~[mockito-core-2.15.0.jar:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na] …Run Code Online (Sandbox Code Playgroud)