Spring Boot and Spock Integration Testing
I am new to Spring Boot and while testing a REST endpoint with SPOCK came across issue # 24405727 I tried the exact configuration but I get the following exception.
java.lang.IllegalStateException: of The WebApplicationContext for test context The [ TestContext @ 21a722ef testClass = HelloControllerSpec, testInstance = com.hello.HelloControllerSpec@63e68a2b , TestMethod = [null], TestException = [null], mergedContextConfiguration = [ WebMergedContextConfiguration @ 3479404a testClass = HelloControllerSpec , locations = '{}', classes = '{class com.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', resourceBasePath = 'src / main / webapp', contextLoader = 'org.springframework. boot.test.SpringApplicationContextLoader ', parent = [null]]] must be configured with a MockServletContext.
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary (ServletTestExecutionListener.java:111)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance (ServletTestExecutionListener.java:74)
at org.springframework.test.context.TestContextManager.prepareTestInstance (TestContextManager.java:312)
at org.spockframework.spring.SpringTestContextManager.prepareTestInstance (SpringTestContextManager.java:49)
at org.spockframework.spring.SpringInterceptor.interceptSetupMethod (SpringInterceptor.java:42)
at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept (AbstractMethodInterceptor.java:28)
at org.spockframework.runtime.extension.MethodInvocation.proceed (MethodInvocation.java:84)
at org.spockframework.util.ReflectionUtil.invokeMethod (ReflectionUtil.java:138)
at org.spockframework.util.ReflectionUtil.invokeMethod (ReflectionUtil.java:138)
at org.spockframework.util.ReflectionUtil.invokeMethod (ReflectionUtil.java:138)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass (JUnitTestClassExecuter.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute (JUnitTestClassExecuter.java:49)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass (JUnitTestClassProcessor.java:69)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass (SuiteTestClassProcessor.java:48)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch (ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch (ReflectionDispatch.java:24)
at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch (ContextClassLoaderDispatch.java:32)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter $ DispatchingInvocationHandler.invoke (ProxyDispatchAdapter.java:93)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass (TestWorker.java:105)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch (ReflectionDispatch.java:35)
at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch (ReflectionDispatch.java:24)
at org.gradle.messaging.remote.internal.hub.MessageHub $ Handler.run (MessageHub.java:355)
at org.gradle.internal.concurrent.DefaultExecutorFactory $ StoppableExecutorImpl $ 1.run (DefaultExecutorFactory.java:64)
at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask (ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:908)
at java.lang.Thread.run (Thread.java:662)
Below is my Groovy spock spec
@ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = Application.class)
@WebAppConfiguration
@IntegrationTest
class HelloControllerSpec extends Specification {
def "Greeting test"() {
when:
ResponseEntity entity = new RestTemplate().getForEntity("http://localhost:8080", String.class);
then:
entity.statusCode == HttpStatus.OK
}
} `
Any help is appreciated.
+2
source to share
No one has answered this question yet
See similar questions:
or similar: