SpringBoot: how to run tests twice, with two diffe

2019-08-30 03:00发布

I am writing a SpringBoot application using a JMS MOM. My application supports two kinds of JMS: EMS and AMQ

My application has many Junit Tests. Of course, whether I use EMS or AMQ the tests are exactly the same and the expected results are also exactly the same. The only difference is the configuration file used.

@RunWith(SpringRunner.class)
@TestPropertySource(locations="classpath:application.yaml")
@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class)
public class MyTest {

    @SpringBootApplication
    @ComponentScan("com.mytest")
    static class Application {
    }


    @Test
    public void test() {
        ...
    }

}

What I would like to be able to do is to run my tests twice, one time with an EMS config and one time with and AMQ config: How should I do?

FYI, I am using Maven to build my application. A solution based on a maven trick would be perfectly acceptable for me

Thank you for help

1条回答
Deceive 欺骗
2楼-- · 2019-08-30 03:57

It sounds like a task for a building tool that you using.

For example, for Maven you can write specific test tasks with different active profiles, something like this:

mvn clean test -Dspring.profiles.active=kafka
mvn clean test -Dspring.profiles.active=rabbitmq
mvn clean test -Dspring.profiles.active=activemq

and collect necessary properties in files: application-{profile}.properties


This articles can help you:

查看更多
登录 后发表回答