我正在尝试了解 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 。我应该注意的
Automatically searches for a @SpringBootConfiguration when nested @Configuration is not used, and no explicit classes are specified.
我的主类用 @SpringBootApplication
进行注释,这是一个配置注释。
关于java - Spring Boot 应用程序的测试如何进行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47979344/