指定要运行的Junit测试

时间:2015-07-14 05:56:38

标签: maven jenkins junit

我正在使用Selenium Junit Maven和Jenkins,指定运行哪些测试的最佳方法是什么? 我试过Categories但发现它太复杂了。有没有简单的方法来指定要运行的测试方法/类?

1 个答案:

答案 0 :(得分:3)

虽然我认为类别是可行的方法,但您也可以在surefire插件配置中include/exclude测试类。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <configuration>
      <includes>
        <include>Sample.java</include>
      </includes>
    </configuration>
  </plugin>

如果要执行single test method,可以指定test属性

mvn -Dtest=TestCircle#mytest test

您也可以在pom.xml中设置test属性,并在不同的配置文件中设置不同,但最后,类别优于此类,并且是一个很好的测试套件设计实践。