2016-07-01 10 views
1

私はSpringブートアプリケーションの統合テストを行っています。依存関係(およびクラスパスジャー)に基づいて春の起動は、起動するサーバーを選択します:(春は起動のみです。起動時のWebは、起動時に春の起動があるか、スターター - 桟橋)複数の埋め込みサーバを使ってspring-boot統合テストを実行する方法

私は多くの異なるサーバーで動作するはずのフィルターを書いています。私はどのサーバーにも依存関係をコンパイルしていませんが、私は多くのサーバーで自分のコードをテストしたいと思います。どうすればいい?

確かに、ある種のenv変数に基づいてgradleスクリプトの依存関係を設定してから、別のenv変数値を使ってgradle testを数回呼び出してください。簡単な方法があるので、すべてを一度にテストできますか?テストでプログラムをプログラムで起動するようなのですか?いくつかのgradle/springプラグインを使用していますか?

答えて

0

私の提案はEmbeddedServletContainerAutoConfigurationを無効にして、適切なサーバーの設定をインポートする3台のすべてのサーバー用のテストスコープの依存関係を追加しますが、あなたのテストコードに3つの別々の春ブートアプリケーションクラスを作成し、各アプリケーションのクラスに次のようになります。

@Profile("tomcat") 
@SpringBootApplication(exclude = EmbeddedServletContainerAutoConfiguration.class) 
@Import(EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat.class) 
public class TomcatApplication { 
    public static void main(String[] args) { 
     TomcatApplication.run(TomcatApplication.class, args); 
    } 
} 

@Profile("undertow") 
@SpringBootApplication(exclude = EmbeddedServletContainerAutoConfiguration.class) 
@Import(EmbeddedServletContainerAutoConfiguration.EmbeddedUndertow.class) 
public class UndertowApplication { 
    public static void main(String[] args) { 
     UndertowApplication.run(UndertowApplication.class, args); 
    } 
} 

@Profile("jetty") 
@SpringBootApplication(exclude = EmbeddedServletContainerAutoConfiguration.class) 
@Import(EmbeddedServletContainerAutoConfiguration.EmbeddedJetty.class) 
public class JettyApplication { 
    public static void main(String[] args) { 
     JettyApplication.run(JettyApplication.class, args); 
    } 
} 

次に、適切な@ActiveProfilesを設定してテストを書くと、準備が整うはずです。

関連する問題