2015-03-13 41 views
5

我一张有注释集成测试:春天开机测试 - 通过命令行参数

@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); 
} 

我想通过一些参数来测试上下文。有没有这方面的任何财产?

回答

0

如果您正在使用Maven,您可以通过故障安全插件内部测试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> ...

+0

但我需要通过命令行参数。我使用了一些库,其中存在Spring ApplicationListener,并且此侦听器使用ApplicationEnvironmentPreparedEvent.getArgs()中的命令行参数。我必须做一些getArgs()将返回我的参数。 – wjtk 2015-03-13 13:30:30

+0

这里的问题是集成测试不会调用您的Application.main方法。它只是检查注释。你在哪里使用这些命令参数? – jfcorugedo 2015-03-14 10:10:41