NoscuchMethodError wehn trying to use @SpyBean or @MockBean in SpringBootIntegrationTest
I am trying to use SpyBean in my SpringBoot IntegrationTest. My test class is as follows
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
public class MyTest {
@SpyBean
private MyService myService;
@Test
public void test() {
}
}
My build.gradle for tests is as below
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"
When I try to run thetest, it thows the below exception
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
spring-boot mockito integration-testing powermockito
add a comment |
I am trying to use SpyBean in my SpringBoot IntegrationTest. My test class is as follows
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
public class MyTest {
@SpyBean
private MyService myService;
@Test
public void test() {
}
}
My build.gradle for tests is as below
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"
When I try to run thetest, it thows the below exception
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
spring-boot mockito integration-testing powermockito
What version of Spring Boot are you using?
– Andy Wilkinson
Nov 23 '18 at 7:15
@Andy WilKinson , I use 2.1.0.RELEASE spring boot
– Priya
Nov 23 '18 at 7:21
Remove those dependencies and instead usespring-boo-starter-test
as a dependency. You are using old versions of Mockito and related frameworks. Also do you really need power mock?
– M. Deinum
Nov 23 '18 at 8:10
yea, I need powermock in my test
– Priya
Nov 23 '18 at 8:11
add a comment |
I am trying to use SpyBean in my SpringBoot IntegrationTest. My test class is as follows
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
public class MyTest {
@SpyBean
private MyService myService;
@Test
public void test() {
}
}
My build.gradle for tests is as below
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"
When I try to run thetest, it thows the below exception
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
spring-boot mockito integration-testing powermockito
I am trying to use SpyBean in my SpringBoot IntegrationTest. My test class is as follows
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
public class MyTest {
@SpyBean
private MyService myService;
@Test
public void test() {
}
}
My build.gradle for tests is as below
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"
When I try to run thetest, it thows the below exception
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
spring-boot mockito integration-testing powermockito
spring-boot mockito integration-testing powermockito
asked Nov 23 '18 at 6:46
PriyaPriya
10714
10714
What version of Spring Boot are you using?
– Andy Wilkinson
Nov 23 '18 at 7:15
@Andy WilKinson , I use 2.1.0.RELEASE spring boot
– Priya
Nov 23 '18 at 7:21
Remove those dependencies and instead usespring-boo-starter-test
as a dependency. You are using old versions of Mockito and related frameworks. Also do you really need power mock?
– M. Deinum
Nov 23 '18 at 8:10
yea, I need powermock in my test
– Priya
Nov 23 '18 at 8:11
add a comment |
What version of Spring Boot are you using?
– Andy Wilkinson
Nov 23 '18 at 7:15
@Andy WilKinson , I use 2.1.0.RELEASE spring boot
– Priya
Nov 23 '18 at 7:21
Remove those dependencies and instead usespring-boo-starter-test
as a dependency. You are using old versions of Mockito and related frameworks. Also do you really need power mock?
– M. Deinum
Nov 23 '18 at 8:10
yea, I need powermock in my test
– Priya
Nov 23 '18 at 8:11
What version of Spring Boot are you using?
– Andy Wilkinson
Nov 23 '18 at 7:15
What version of Spring Boot are you using?
– Andy Wilkinson
Nov 23 '18 at 7:15
@Andy WilKinson , I use 2.1.0.RELEASE spring boot
– Priya
Nov 23 '18 at 7:21
@Andy WilKinson , I use 2.1.0.RELEASE spring boot
– Priya
Nov 23 '18 at 7:21
Remove those dependencies and instead use
spring-boo-starter-test
as a dependency. You are using old versions of Mockito and related frameworks. Also do you really need power mock?– M. Deinum
Nov 23 '18 at 8:10
Remove those dependencies and instead use
spring-boo-starter-test
as a dependency. You are using old versions of Mockito and related frameworks. Also do you really need power mock?– M. Deinum
Nov 23 '18 at 8:10
yea, I need powermock in my test
– Priya
Nov 23 '18 at 8:11
yea, I need powermock in my test
– Priya
Nov 23 '18 at 8:11
add a comment |
1 Answer
1
active
oldest
votes
To use @MockBean
and @SpyBean
, Spring Boot 2.1.0 requires Mockito 2. Your dependency configuration has downgraded Mockito to 1.10.
I think you have two choices:
- Avoid using Powermock so that you can use the up-to-date version of Mockito required by
@MockBean
and@SpyBean
- Avoid using
@MockBean
and@SpyBean
to accommodate Powermock's need for an old version of Mockito
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441826%2fnoscuchmethoderror-wehn-trying-to-use-spybean-or-mockbean-in-springbootintegra%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To use @MockBean
and @SpyBean
, Spring Boot 2.1.0 requires Mockito 2. Your dependency configuration has downgraded Mockito to 1.10.
I think you have two choices:
- Avoid using Powermock so that you can use the up-to-date version of Mockito required by
@MockBean
and@SpyBean
- Avoid using
@MockBean
and@SpyBean
to accommodate Powermock's need for an old version of Mockito
add a comment |
To use @MockBean
and @SpyBean
, Spring Boot 2.1.0 requires Mockito 2. Your dependency configuration has downgraded Mockito to 1.10.
I think you have two choices:
- Avoid using Powermock so that you can use the up-to-date version of Mockito required by
@MockBean
and@SpyBean
- Avoid using
@MockBean
and@SpyBean
to accommodate Powermock's need for an old version of Mockito
add a comment |
To use @MockBean
and @SpyBean
, Spring Boot 2.1.0 requires Mockito 2. Your dependency configuration has downgraded Mockito to 1.10.
I think you have two choices:
- Avoid using Powermock so that you can use the up-to-date version of Mockito required by
@MockBean
and@SpyBean
- Avoid using
@MockBean
and@SpyBean
to accommodate Powermock's need for an old version of Mockito
To use @MockBean
and @SpyBean
, Spring Boot 2.1.0 requires Mockito 2. Your dependency configuration has downgraded Mockito to 1.10.
I think you have two choices:
- Avoid using Powermock so that you can use the up-to-date version of Mockito required by
@MockBean
and@SpyBean
- Avoid using
@MockBean
and@SpyBean
to accommodate Powermock's need for an old version of Mockito
answered Nov 23 '18 at 11:43
Andy WilkinsonAndy Wilkinson
59.9k9144151
59.9k9144151
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441826%2fnoscuchmethoderror-wehn-trying-to-use-spybean-or-mockbean-in-springbootintegra%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What version of Spring Boot are you using?
– Andy Wilkinson
Nov 23 '18 at 7:15
@Andy WilKinson , I use 2.1.0.RELEASE spring boot
– Priya
Nov 23 '18 at 7:21
Remove those dependencies and instead use
spring-boo-starter-test
as a dependency. You are using old versions of Mockito and related frameworks. Also do you really need power mock?– M. Deinum
Nov 23 '18 at 8:10
yea, I need powermock in my test
– Priya
Nov 23 '18 at 8:11