Я пытаюсь использовать SpyBean в моем тесте интеграции SpringBoot.Мой тестовый класс выглядит следующим образом:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
public class MyTest {
@SpyBean
private MyService myService;
@Test
public void test() {
}
}
Мой build.gradle для тестов выглядит следующим образом
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.7.4'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.7.4'
testCompile "org.powermock:powermock-classloading-xstream:1.7.4"
Когда я пытаюсь запустить тест, он выдает следующее исключение
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyService' Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.mockito.MockSettings.verificationStartedListeners([Lorg/mockito/listeners/VerificationStartedListener;)Lorg/mockito/MockSettings;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:273)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1239)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1166)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593)
... 80 more
Caused by: java.lang.NoSuchMethodError: org.mockito.MockSettings.verificationStartedListeners([Lorg/mockito/listeners/VerificationStartedListener;)Lorg/mockito/MockSettings;
at org.springframework.boot.test.mock.mockito.SpyDefinition.createSpy(SpyDefinition.java:100)
at org.springframework.boot.test.mock.mockito.MockitoPostProcessor.createSpyIfNecessary(MockitoPostProcessor.java:355)
at org.springframework.boot.test.mock.mockito.MockitoPostProcessor$SpyPostProcessor.postProcessAfterInitialization(MockitoPostProcessor.java:489)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:434)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1749)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
... 89 more