I just moved to Spring Boot 1.4.0 to use the new test features. However, I seem to be unable to use them in conjunction 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 issue is that the annotation does not even seem to be able to find the MainWebApplication.class
(sitting on a package higher in the hierarchy), and consequently, there is no context, so nothing to Autowire
. I realize this is pretty new stuff, But documentation so far is not very good, so probably, this question will help others as well.