I want to test my Controller using @WebMvcTest
and mock the dependencies, but Spring Boot's AutoConfiguration loads my Couchbase (Spring Data) configuration automatically. Couchbase is not available on some platforms which run the test, so the Test class will throw an Exception. How can I exclude some classes from the AutoConfiguration mechanism?
I tried the excludeFilters
option of @WebMvcTest
and @ActiveProfile
to load another Application Context, but that didn't work.
Test configuration:
@RunWith(SpringRunner.class)
@WebMvcTest(value = ExchangeJobImportController.class, excludeFilters = @ComponentScan.Filter(classes = CouchbaseConfiguration.class))
@ActiveProfiles("test")
public class ExchangeJobImportControllerTest {
...
}
Couchbase Configuration:
@Configuration
@EnableCouchbaseAuditing
@EnableConfigurationProperties({CouchbaseProperties.class})
@EnableCouchbaseRepositories(basePackages = "com....")
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
...
}