spring 启动应用程序的测试如何工作
How do the tests work for spring boot apps
我正在尝试了解 spring 引导以及所有与它相关的工作。目前我正在为集成测试而苦苦挣扎,所以我去看了 spring-boot-samples. I started to look at spring-boot-sample-testng
在此集成测试示例中,我没有看到任何对 SampleTestNGApplication class 的引用,其中主要方法是。
@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中class.
答案在SpringBootTest doc中。我应该注意
Automatically searches for a @SpringBootConfiguration when nested @Configuration is not used, and no explicit classes are specified.
我的主 class 是用 @SpringBootApplication
注释的,这是一个配置注释。
我正在尝试了解 spring 引导以及所有与它相关的工作。目前我正在为集成测试而苦苦挣扎,所以我去看了 spring-boot-samples. I started to look at spring-boot-sample-testng
在此集成测试示例中,我没有看到任何对 SampleTestNGApplication class 的引用,其中主要方法是。
@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中class.
答案在SpringBootTest doc中。我应该注意
Automatically searches for a @SpringBootConfiguration when nested @Configuration is not used, and no explicit classes are specified.
我的主 class 是用 @SpringBootApplication
注释的,这是一个配置注释。