简体   繁体   中英

How to ignore multiple JUnit Test Classes?

I'm trying to execute some test cases in an very big applications. There are 100s of error test cases and some of them

  • requires specific property files which won't be available in development environment.
  • are outdated, but can't be simply removed

Is there anyway in which I can provide an XML or any other input which can list all the test classes to ignore?

I'm using maven with surefire plugin for executing test cases.

PS

I'm aware of @ignore annotation which can be used to ignore test cases or test classes. I don't want to use this because it requires changing each class which I want to ignore.

What I want is a single configuration file where I can mention all the classes to ignore.

There are 2 options:

1.To skip running the tests for a particular project, you can set skipTests to true.

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

2) Also you can skip the tests via command line by executing the following command:

mvn install -DskipTests

You can potentially create a TestSuite that includes all the tests you do want to run, and then specify to Maven that it should use that particular Test Suite with:

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

with TestSuite.java being the name of the suite you wish to run. You could potentially have two and just switch that setting in your pom.xml when you wish to target only certain classes. This setting affects what tests are executed when you run mvn test .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM