Я на начальном этапе спока и Groovy, я пытаюсь протестировать одно простое приложение с весенней загрузкой и получаю
Ниже мой код Java и Groovy с деталями исключения
Condition not satisfied:
mvc.perform(get('/hello')).andExpect(status().isOk())
| |
| groovy.lang.MissingMethodException: No signature of method: org.spockframework.controllers.TestControllerSpec.get() is applicable for argument types: (java.lang.String) values: [/hello]
| Possible solutions: getAt(java.lang.String), grep(), grep(java.lang.Object), wait(), Spy(), getMvc()
org.springframework.test.web.servlet.MockMvc@6bb68f5
at org.spockframework.controllers.TestControllerSpec.spring context loads for web mvc slice(TestControllerSpec.groovy:28)
Caused by: groovy.lang.MissingMethodException: No signature of method: org.spockframework.controllers.TestControllerSpec.get() is applicable for argument types: (java.lang.String) values: [/hello]
Possible solutions: getAt(java.lang.String), grep(), grep(java.lang.Object), wait(), Spy(), getMvc()
and above exception comes when some argument is missing don't what argument and how to pass argument below is my code
TestController.java
@RequestMapping(value = "/hello")
@ResponseBody
public String sayHelloWorld() {
return "hello world";
}
TestControllerSpec.groovy
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import spock.lang.Specification
import spock.lang.Unroll
import spock.mock.DetachedMockFactory
@ContextConfiguration
@WebMvcTest(TestController)
class TestControllerSpec extends Specification {
@Autowired
MockMvc mvc;
@Unroll
def "spring context loads for web mvc slice"() {
expect: "controller is available"
mvc.perform(get('/hello')).andExpect(status().isOk())
}
@TestConfiguration
static class MockConfig {
def detachedMockFactory = new DetachedMockFactory();
}
}
Я уверен, что в моем коде чего-то не хватает