这就是我设置值的方式
<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/