leo.fcx
leo.fcx

Reputation: 6467

Run my integration tests with a different *.properties file using Spring 4.0.6.RELEASE

I am currently using Spring 4.0.6.RELEASE and have the following Spring configuration file:

@Configuration
@PropertySource({"classpath:config.properties"})
public class MyServiceConfig {
...

I was wondering if there is a way to run integration tests for my component-annotated-classes with a different properties file (let's say test-config.properties) in order to give different values for my value and autowired annotated properties and methods.

NOTE: I know that Spring 4.1.x comes with @TestPropertySource which helps to achieve it. But upgrading Spring to later versions is not an option.

Upvotes: 1

Views: 1100

Answers (1)

Branislav Lazic
Branislav Lazic

Reputation: 14816

Yes. Specify "profile" for integration tests.

@Configuration
@PropertySource({"classpath:test-config.properties"})
@Profile("integration-test")
public class MyServiceTestConfig {
...

In order to use this profile when testing repository use @ActiveProfiles annotation

@ActiveProfiles("integration-test")
@RunWith(SpringJUnit4ClassRunner.class)
public class MyRepositoryTest {
...

Upvotes: 3

Related Questions