SpringBoot:如何使用两个不同的配置文件运行两次测试 [英] SpringBoot: how to run tests twice, with two different config files

查看:70
本文介绍了SpringBoot:如何使用两个不同的配置文件运行两次测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JMS MOM 编写 SpringBoot 应用程序.我的应用程序支持两种 JMS:EMS 和 AMQ

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

我的应用程序有很多 Junit 测试.当然,无论我用EMS还是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() {
        ...
    }

}

我希望能够做两次测试,一次使用 EMS 配置,一次使用 AMQ 配置:我该怎么做?

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?

仅供参考,我正在使用 Maven 构建我的应用程序.基于 maven 技巧的解决方案对我来说是完全可以接受的

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

感谢您的帮助

推荐答案

这听起来像是您使用的构建工具的任务.

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

例如,对于 Maven,您可以使用不同的活动配置文件编写特定的测试任务,如下所示:

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

并在文件中收集必要的属性:application-{profile}.properties

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


这篇文章可以帮助您:

mvn 配置文件:介绍简介

mvn 不同的环境:构建不同环境

这篇关于SpringBoot:如何使用两个不同的配置文件运行两次测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆