Software Qustions
Software Qustions

Reputation: 221

Specify which Junit test to run

I am using Selenium Junit Maven and Jenkins, what is the best way to specify which tests to run? I tried Categories but found it too complicated. Is there an easy way to specify which test methods/class to run?

Upvotes: 3

Views: 110

Answers (1)

Gerald Mücke
Gerald Mücke

Reputation: 11132

Although I believe Categories is the way to go, you could alternatively include/exclude test classes in the surefire plugin configuration.

<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>

If you want to execute a single test method, you can specify the test property

mvn -Dtest=TestCircle#mytest test

You could set the test property in your pom.xml as well and set it differently in different profiles, but in the end, categories is superior to that and a good test suite design practice.

Upvotes: 3

Related Questions