我正在努力进行集成测试,所以我去了spring-boot-samples . 我开始看spring-boot-sample-testng
在这个集成测试示例中,我没有看到任何对SampleTestNGApplication类的引用,其中main方法是 .
@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类中的 .
2 回答
你正在调用
"/"
调用SampleController,它有一个方法:由
HelloWorldService
返回"Hello World"答案是SpringBootTest doc . 我应该注意到
我的主类使用
@SpringBootApplication
进行注释,这是一个配置注释 .