mikeb
mikeb

Reputation: 11267

Spring Boot Test - I do not want to load all @Configuration classes for a particular test

I have a half-dozen classes in an application annotated with @Configuration and am writing unit tests.

I have one @Configuration class that sets up Quartz, and one that deals with setting up Camel.

In my Camel unit test, I only want to load the @Configuration class that sets up Camel, because it does not care about Quartz (and vice-versa).

How do I tell my Spring Boot test to only bootstrap certain configuration-annotated classes? @TestConfiguration does not do that...

@Configuration
public class QuartzConfig {
    ...
}

@Configuration
public class CamelConfig {
    ...
}

@RunWith(SpringRunner.class)
@SpringBootTest
@SOME ANNOTATION THAT SAYS ONLY LOAD CamelConfig.class???????
public class CamelOnlyTest {
    ....
}

Upvotes: 9

Views: 9482

Answers (1)

ThisIsNoZaku
ThisIsNoZaku

Reputation: 2443

By using the classes parameter of @SpringBootTest, you can specify which classes to use for configuration.

From the docs:

public abstract Class[] classes

The annotated classes to use for loading an ApplicationContext.

Upvotes: 8

Related Questions