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.
The current version of Spock is incompatible with Spring Boot 1.4's @SpringBootTest
annotation, you should upgrade your Spock version to 1.1 if you wish to use the new annotations.
For more details, see this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With