@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 对我来说似乎不正确。凭据应该在“application.yml”中,并且应该已经模拟了身份验证调用。请建议编写此测试的更好方法。