I just switched to Spring Boot 1.4.0 to use the new test features. However, I seem to be unable to use them with the Spock Framework. Consider the following Spec:
@SpringBootTest(classes=[MainWebApplication.class], webEnvironment =SpringBootTest.WebEnvironment.RANDOM_PORT)
class RestTemplateExampleSpec extends Specification{
@Autowired
private TestRestTemplate restTemplate
def "Web application is Reachable and Status is 200 - OK"(){
when: "The root address is called"
def response = restTemplate.getForObject("/", String.class)
then: "The status code is 200 - OK"
response.statusCode == HttpStatus.OK
}
def "Endpoint /admin/users is available"(){
when: "/admin/users is called"
def response = restTemplate.getForEntity("/admin/users", String.class)
then: "The status code is 200 - OK"
response.statusCode == HttpStatus.OK
}
}
The problem is that the annotation cannot even find MainWebApplication.class(sits on the package above in the hierarchy), and therefore there is no context, so nothing is needed Autowire. I understand that this is fairly new material, but the documentation is not very good so far, so this question will probably also help others.
source
share