2016-09-09 5 views
41

@SpringApplicationConfigurationと@WebIntegrationはSpring Boot Framework 1.4の時点で推奨されていないので、適切な注釈は何ですか?私は単体テストで遊んでいます。@SpringApplicationConfiguration、@WebIntegrationはSpring Boot Frameworkでは推奨されていないので、適切な注釈は何ですか?

+4

@SpringBootTest(webEnvironment = WebEnvironment.MOCK) – Ulises

+0

がhttpsを見てみましょう:に置き換え、多くの一つとして

@RunWith(SpringRunner.class) @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) public class MyTest { } 

彼らは、次のような基本的なサンプルを記述します://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4 – Lu55

答えて

30

は非推奨のクラスのJavaDocに見てみましょう:

* @deprecated as of 1.4 in favor of 
* {@link org.springframework.boot.test.context.SpringBootTest} with 
* {@code webEnvironment=RANDOM_PORT} or {@code webEnvironment=DEFINED_PORT}. 
*/ 
... 
@Deprecated 
public @interface WebIntegrationTest { 

* @deprecated as of 1.4 in favor of {@link SpringBootTest} or direct use of 
* {@link SpringBootContextLoader}. 
*/ 
... 
@Deprecated 
public @interface SpringApplicationConfiguration { 

もTestRestTemplateの置き換え(ありますか)?

はい、ここにある:

* @deprecated as of 1.4 in favor of 
* {@link org.springframework.boot.test.web.client.TestRestTemplate} 
*/ 
@Deprecated 
public class TestRestTemplate extends RestTemplate { 
+1

@Lisa正解とマークする必要があります。 – Anand

8

あなたが@EnableAutoConfigurationや@SpringBootApplicationを使用することができます。

参照してくださいあなたは

@SpringBootTest(webEnvironment = 'あなたの値')または単に@SpringBootTestを使用することができ、テストの目的のために:RESTをテストするための

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html

を、あなたが使用することができます@ RestClientTestとRestTemplateBuilderを構成します。

0

あなたはこのアノテーションを使用する必要があります開始する

@ContextConfiguration(classes = main_class) 
+0

これは、統合テスト中には機能しません。私のアプリケーションは、プロパティファイルからデータベースのURLパラメータを取得できません。 –

14

良い場所は、おそらく今ある: Testing improvements in Spring Boot 1.4

@RunWith(SpringJUnit4ClassRunner.class) 
@SpringApplicationConfiguration(MyApp.class) 
@WebIntegrationTest 
public class MyTest { 
} 
+1

ApplicationConfigurationがMyApp.classクラスにあることを知っているあなたの上位バージョンはどうですか?私がそれを実装すると、それはapplicationContextをロードするのに失敗します。 – Nali

+0

良い質問ですが、私は知らないのですが、それは一度に1つのランニングアプリケーションだけかもしれません。 – user1767316

関連する問題