I am writing a test case for my controller in spring boot below is my controller
@RestController
public class HelloController {
@RequestMapping("/hello")
public String helloWorld(){
return "hello world";
}
}
Now I writing the Spock test case for the same also as shown below
package groovy
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import spock.lang.Narrative
import spock.lang.Specification
import spock.lang.Title
@Title("Application Specification")
@Narrative("Specification which beans are expected")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class HelloControllerTest extends Specification {
@Autowired
private HelloController helloController
def "when get is performed then the response has status 200 and content is 'hello world'"() {
expect: "Status is 200 and the response is 'hello world'"
mvc.perform(get("/hello"))
.andExpect(status().isOk())
.andReturn()
.response
}
}
but in response I am getting the below exception please advise how to overcome from the same Condition failed with Exception:
mvc.perform(get("/hello")) .andExpect(status().isOk()) .andReturn() .response
| |
null groovy.lang.MissingMethodException: No signature of method: groovy.HelloControllerTest.get() is applicable for argument types: (java.lang.String) values: [/hello]
Possible solutions: getAt(java.lang.String), grep(), grep(java.lang.Object), wait(), Spy(), any()
at groovy.HelloControllerTest.when get is performed then the response has status 200 and content is 'hello world'(HelloControllerTest.groovy:26)
at groovy.HelloControllerTest.when get is performed then the response has status 200 and content is 'hello world'(HelloControllerTest.groovy:27)
Caused by: groovy.lang.MissingMethodException: No signature of method: groovy.HelloControllerTest.get() is applicable for argument types: (java.lang.String) values: [/hello]
Possible solutions: getAt(java.lang.String), grep(), grep(java.lang.Object), wait(), Spy(), any()
at groovy.HelloControllerTest.when get is performed then the response has status 200 and content is 'hello world'(HelloControllerTest.groovy:26)