我们的目标是对可以在指定时间内禁用的系统进行验收测试,并确保系统被禁用并恢复启用。
我们的计划是:
我们喜欢保持对启用和禁用情况的测试解耦,因此必须在maven本身中或作为某种插件类型的解决方案引入睡眠。
问题:如何指定maven运行测试目标的顺序,并在两者之间添加参数化延迟,这将提供给Selenium?
发布于 2016-08-16 16:01:20
您可以应用以下配置:
maven-surefire-plugin或maven-failsafe-plugin (更适合于集成测试,在本用例中听起来更合适),通过它的包括/排除机制执行第一组测试,作为这个插件的第一次执行maven-surefire-plugin (或maven-failsafe-plugin)配置为执行一个示例测试用例,该测试用例的唯一目的是在确定(或可配置)时间内,再次通过包括/排除机制执行该插件(Maven将根据pom.xml文件声明尊重执行顺序)。maven-surefire-plugin (或maven-failsafe-plugin)配置为执行第二组测试(或本用例中的单个检查测试),同样通过包括/排除执行第三次执行(然后作为最后一次执行)。在同一个阶段使用相同的插件并执行几次将确保在Maven执行期间使用声明顺序将按照。
下面是上述方法的示例片段:
<profile>
<id>check-test</id>
<build>
<properties>
<sleep.time>2000</sleep.time>
</properties>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>first-execution</id>
<phase>test</phase>
<configuration>
<includes>
<include>*FirstTestsSample.java</include>
</includes>
</configuration>
</execution>
<execution>
<id>second-execution</id>
<phase>test</phase>
<configuration>
<includes>
<include>SleepTest.java</include>
</includes>
<systemPropertyVariables>
<sleepParam>${sleep.time}</sleepParam>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>third-execution</id>
<phase>test</phase>
<configuration>
<includes>
<include>CheckTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>注意,为了清洁起见,我将所有内容封装在Maven 配置文件中,因为您可能不希望将此行为作为默认构建的一部分,而只在需要时(或作为CI作业的一部分)执行。
如果需要配置睡眠时间,则可以通过configuration选项配置每个execution的相关systemPropertyVariables部分。
然后,您可以按以下方式调用您的构建:
mvn clean verify -Pcheck-test -Dsleep.time=3000其中,-P通过其id启用配置文件,我们还通过命令行重写sleep.time属性的默认值,然后作为sleepParam系统变量的值传递,该值可以通过System.gerProperty("sleepParam")调用从System.gerProperty("sleepParam")代码中获取。
另外,请注意,maven-failsafe-plugin可能更适合您的场景,因为它更好地处理集成/验收测试的执行后,就像它的官方页面中所描述的那样,尽管您的用例仍然可以由“`maven surefire-plugin”提供。
https://stackoverflow.com/questions/38978372
复制相似问题