我有集成测试和注释:
@WebAppConfiguration
@ActiveProfiles("integration")
@ContextConfiguration(loader = SpringApplicationContextLoader, classes = [MyApplication])
@IntegrationTest(["server.port=0"])
我可以将例如server.port属性传递给测试上下文,但有没有办法传递命令行参数?我的应用程序正常启动:
public static final void main(String[] args) {
SpringApplication.run(AnkaraCollectorApplication.class, args);
}
我想传递一些args来测试上下文。这有什么属性吗?
答案 0 :(得分:0)
如果您使用的是maven,则可以在failafe插件中传递测试JVM args:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
...
<configuration>
<argLine> whatever you want: -DhelloWorld=Test </argLine>
</configuration>
...
您还可以根据正在执行的maven配置文件设置此JVM参数:
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Development JVM arguments -->
<test-arguments>-Dhello=true</test-arguments>
<!-- Default environment -->
<environment>develop</environment>
</properties>
</profile>
...
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
...
<configuration>
<argLine>${test-arguments}</argLine>
</configuration>
...
答案 1 :(得分:0)
尝试在测试类中进行设置:
static {
System.setProperty("key", "value");
}