java - maven Surefire 插件不注入(inject)系统属性

标签 java maven maven-surefire-plugin

这就是我设置值的方式

   <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <systemProperties>
                        <property>spring.active.profiles</property>
                        <value>Test</value>
                    </systemProperties>
                    <systemPropertyVariables>
                        <spring.active.profiles>development</spring.active.profiles>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>

测试失败

@Test
public void testGetProfile() throws Exception {
    assertEquals("development", System.getProperty("spring.active.profiles"));
}

我明白了

java.lang.AssertionError: 
Expected :development
Actual   :null

我在这里缺少什么?

最佳答案

没有什么问题!

在控制台 mvn 测试中运行它

或者

Eclipse --> [项目] --> 运行方式 --> Maven 测试

如果您通过 Eclipse --> Run as --> JUnit 运行此测试,则该测试可能会失败,有时此操作会忽略 pom.xml 变量。

关于java - maven Surefire 插件不注入(inject)系统属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23413498/

相关文章:

java - 我们是否应该避免显式使用 wait/notify/notifyAll

java - 通用通配符调用无法编译

maven - Liferay 的父 Pom 构建问题

java - maven-surefire-plugin 不适用于配置文件

java - Maven surefire environmentVariables 在一台机器上不起作用

java - CDI 生产商未获得资格认证

java - Thrift 版本之间的数据格式兼容性

java - 有没有办法使用 Maven 和 Junit 5 来​​暂存数据?

java - Maven-assembly-plugin 失败,超过 GC 开销限制

java - Maven多模块项目添加Axis2导致的依赖冲突如何解决