且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

排除特定测试在jUnit中并行运行

更新时间:2022-05-23 22:20:12

在原始测试短语中排除这2个测试,然后使用在单线程中运行的这2个类创建一个新的执行? :)

Exclude those 2 tests in the original test phrase and then create a new execution with those 2 classes running in single thread? :)

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>path/to/your/class/badtestclass1.java</exclude>
            <exclude>path/to/your/class/badtestclass2.java</exclude>
        </excludes>
        <parallel>classes</parallel>
    </configuration>

    <executions>
        <execution>
            <id>single-thread-test</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration>
                <includes>
                    <include>path/to/your/class/badtestclass1.java</include>
                    <include>path/to/your/class/badtestclass2.java</include>
                </includes>
                <threadCount>1</threadCount>
            </configuration>
        </execution>
    </executions>
  </plugin>