wjt*_*jtk 5 java spring spring-test spring-boot
我有集成测试和注释:
@WebAppConfiguration
@ActiveProfiles("integration")
@ContextConfiguration(loader = SpringApplicationContextLoader, classes = [MyApplication])
@IntegrationTest(["server.port=0"])
Run Code Online (Sandbox Code Playgroud)
我可以传递例如server.port属性来测试上下文,但有没有办法传递命令行参数?我的应用程序正常启动:
public static final void main(String[] args) {
SpringApplication.run(AnkaraCollectorApplication.class, args);
}
Run Code Online (Sandbox Code Playgroud)
我想传递一些args来测试上下文.这有什么财产吗?
如果您使用 Maven,您可以在故障安全插件中传递测试 JVM 参数:
<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>
...
归档时间: |
|
查看次数: |
3017 次 |
最近记录: |