@SpringBootTest(webEnvironment = RANDOM_PORT)
@ActiveProfiles("test")
class ContextLoadingSpec extends Specification {
@Autowired
TestRestTemplate testRestTemplate
def '/ should load the context'() {
when:
ResponseEntity<Object> entity = testRestTemplate.getForEntity('/', Object.class)
then:
entity.statusCode == HttpStatus.OK
}
@TestConfiguration
static class Config {
@Bean
RestTemplateBuilder restTemplateBuilder() {
return new RestTemplateBuilder()
.basicAuthorization('user', 'xxxxxxxx')
}
}
}
创建TestConfiguration对我来说似乎不对。凭据应该在&#39; application.yml&#39;并且应该模拟身份验证调用。请建议更好的方法来编写此测试。