Lucas
Lucas

Reputation: 1271

How to reuse my configurations and exclude another one in SpringBoot Test?

How can I reuse my main configurations but exclude some..?

Like:

@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...

}

In the sample above I want to exclude ConfigThree.class and use ConfigThreeTest.class

Upvotes: 0

Views: 1267

Answers (2)

Jyothrilinga K
Jyothrilinga K

Reputation: 327

In your MyTests class, you can specify which class(es) to be used for the configuration.

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

Upvotes: 2

Zubair Nabi
Zubair Nabi

Reputation: 1046

Try using this

@SpringBootApplication(exclude = {demo.class})

Upvotes: -1

Related Questions