tho*_*omi 5 spring spring-test spock spring-boot
我刚刚转到Spring Boot 1.4.0来使用新的测试功能.但是,我似乎无法将它们与Spock Framework结合使用.请考虑以下规范:
@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
}
}
Run Code Online (Sandbox Code Playgroud)
问题是注释似乎甚至无法找到MainWebApplication.class(坐在层次结构中较高的包上),因此,没有上下文,所以没有任何内容Autowire.我意识到这是一个非常新的东西,但到目前为止的文档并不是很好,所以可能这个问题也会对其他人有所帮助.
| 归档时间: |
|
| 查看次数: |
3353 次 |
| 最近记录: |