我想Maven只有在定义参数时才运行测试阶段。 例如:Maven:在运行测试之前检查参数
mvn test -Dserver=hosname
如果没有指定的服务器(或空) - 我不想试运行(而不是在MVN测试,也没有在MVN安装)。
我该怎么做?我如何在代码中获取参数的值(例如“server”)?
我想Maven只有在定义参数时才运行测试阶段。 例如:Maven:在运行测试之前检查参数
mvn test -Dserver=hosname
如果没有指定的服务器(或空) - 我不想试运行(而不是在MVN测试,也没有在MVN安装)。
我该怎么做?我如何在代码中获取参数的值(例如“server”)?
档案可以做,在行家ü想要什么
为前:
<profiles>
<profile>
<id>server</id>
<activation>
<property>
<name>server</name>
<value>${hosname}</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
假设你正在使用JUnit:
Assume
检查的属性(见下文@BeforeClass
),并跳过测试的属性为null。
public class RunIfServerProperty {
@BeforeClass
public static void oneTimeSetup() {
Assume.assumeNotNull(System.getProperty("server"));
}
}
轮廓可以这样使用:
<profiles>
<profile>
<activation>
<property>
<name>server</name>
</property>
</activation>
<!-- do whatever you need to do -->
</profile>
</profiles>
使用配置文件这是由设置'skipTests = true'的上述变量激活的?但这听起来更像是一个集成测试,而不是单元测试。 – khmarbaise
这是集成测试。你能否提供一个使用配置文件的例子? – Jonathan