2017-12-26 3 views
0

스프링 부트와 모든 작업을 이해하려고합니다. 현재 통합 테스트에 어려움을 겪고 있으므로 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 클래스에 있음을 어떻게 알 수 있습니까?

+0

https://blog.ccbill.com/spring-boot-and-context-handling에 도움이 될 수 있습니다. – pvpkiran

답변

0
당신이 방법이 SampleController 호출 테스트 "/"에 요구하고있다

:

@GetMapping("/") 

하는 반환에 "Hello World"

0

대답은 SpringBootTest docHelloWorldService으로합니다. 내 관심을 지불 했어야합니다

중첩 된 @Configuration이 사용되지 않고 명시 적 클래스가 지정되지 않은 경우 자동으로 @SpringBootConfiguration을 검색합니다.

주 수업은 구성 주석 인 @SpringBootApplication으로 주석 처리됩니다.

관련 문제