mardi 27 septembre 2016

Java Spring Boot Test: How to exclude java configuration class from test context

I have a java web app with spring boot

When run test I need to exclude some java config files:

Test config (need to include when test run):

@TestConfiguration
@PropertySource("classpath:otp-test.properties")
public class TestOTPConfig {
}

Production config (need to exclude when test run):

 @Configuration
 @PropertySource("classpath:otp.properties")
 public class OTPConfig {
 }

Test class (with explicit config class):

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestAMCApplicationConfig.class)
public class AuthUserServiceTest {
  ....
}

Test config:

@TestConfiguration
@Import({ TestDataSourceConfig.class, TestMailConfiguration.class, TestOTPConfig.class })
@TestPropertySource("classpath:amc-test.properties")
public class TestAMCApplicationConfig extends AMCApplicationConfig {
}

Also have class:

@SpringBootApplication
public class AMCApplication {
}

When test is running OTPConfig used, but I need TestOTPConfig...

How can I do it?

Aucun commentaire:

Enregistrer un commentaire