2017-12-26 23 views
0

私は春の起動とそのすべての作業を理解しようとしています。現時点では統合テストに苦労しているので、私は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クラスにあることをどのように知っていますか?

+0

これはhttps://blog.ccbill.com/spring-boot-and-context-handlingに役立ちます – pvpkiran

答えて

0

による返品 "Hello World" の

@GetMapping("/") 

を。

ネストされた@Configurationが使用されておらず、明示的なクラスが指定されていない場合、@SpringBootConfigurationを自動的に検索します。

私のメインクラスには、構成注釈である@SpringBootApplicationが付いています。

関連する問題