我正在尝试了解 Spring Boot 及其所有相关工作。目前我正在努力进行集成测试,所以我去看了spring-boot-samples。我开始看spring-boot-sample-testng
在这个集成测试示例中,我没有看到对主要方法所在的 SampleTestNGApplication 类的任何引用。
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTests {
@Autowired
private TestRestTemplate restTemplate;
@Test
public void testHome() {
ResponseEntity<String> entity = this.restTemplate.getForEntity("/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("Hello World");
}
}
它怎么知道 main 方法在 SampleTestNGApplication 类中。
答案在SpringBootTest doc 中。我应该注意
未使用嵌套 @Configuration 时自动搜索 @SpringBootConfiguration,并且未指定显式类。
我的主类被注释,@SpringBootApplication
这是一个配置注释。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句