2016-11-16 10 views
0

メインの設定を再利用できますが、いくつかを除外するにはどうすればいいですか?SpringBoot Testで設定を再利用し、別の設定を除外する方法は?

のように:私はConfigThree.classを除外し、使用したい上記のサンプルで

@SpringBootApplication 
@EnableAutoConfiguration 
public class Application { 

    public static void main(String[] args) { 
     new SpringApplicationBuilder(Application.class, 
       ConfigOne.class, 
       ConfigTwo.class, 
       ConfigThree.class //I want to exclude the ConfigThree in my tests and use my own ConfigThreeTest.class 
       ).run(args); 
    } 
} 

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

    //test... 
} 

@Configuration 
public class ConfigThreeTest { 

    //config... 

} 

ConfigThreeTest.class

+0

簡単にはできません。代わりにあなたの設定クラスで '@ Profile'を使うことを考えてください。 –

答えて

2

MyTestsクラスでは、設定に使用するクラスを指定できます。

@SpringBootTest(classes = {ConfigOne.class, ConfigTwo.class},webEnvironment = WebEnvironment.RANDOM_PORT) 
-1

この

を使用してみてください
@SpringBootApplication(exclude = {demo.class}) 
+0

この[リンク](https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4)によると、@SpringBootTestは「最も正しい」方法です。 SpringBootApplicationが必要ですか? – Lucas

+2

クラスパススキャン候補ではなく、自動設定を除外するために 'exclude'が使用されています。 –