【问题标题】:How using parameter "-Dsurefire.skipAfterFailureCount=1" to skip tests after the first crash第一次崩溃后如何使用参数“-Dsurefire.skipAfterFailureCount=1”跳过测试
【发布时间】:2019-10-15 04:23:34
【问题描述】:

我有一个 Maven 测试项目。我在其中使用与上下文相关的测试。我使用 maven-surefire-plugin 来运行测试。 在第一次失败的测试后,我需要让测试停止运行。我通过 -Dsurefire.skipAfterFailureCount=1 找到了一种方法,但它不起作用。也许我做错了什么?下面是我的 pom.xml:

    <properties>
        <selenide.version>5.3.0</selenide.version>
        <junit.jupiter.version>5.5.1</junit.jupiter.version>
        <selenium.java.version>3.141.59</selenium.java.version>
        <allure.junit5.version>2.12.1</allure.junit5.version>
        <aspectj.version>1.8.10</aspectj.version>
        <maven.surefire.plugin.version>3.0.0-M3</maven.surefire.plugin.version>
        <junit.platform.launcher>1.5.2</junit.platform.launcher>
        <junit.jupiter.engine>5.5.2</junit.jupiter.engine>
        <junit.vintage.engine>5.5.2</junit.vintage.engine>
        <allure.maven.version>2.10.0</allure.maven.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.plugin.version}</version>

                <configuration>

                    <argLine>-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    -Dsurefire.skipAfterFailureCount=1
                    </argLine>

                    <systemProperties>

                        <property>

                            <name>allure.results.directory</name>
                            <value>${project.build.directory}/allure-results</value>
                        </property>

                    </systemProperties>

                </configuration>

            </plugin>
        </plugins>
    </build>

我也试过这个选项:

    <build>
        <plugins>
            <plugin>

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven.surefire.plugin.version}</version>

                <configuration>
                    <skipAfterFailureCount>1</skipAfterFailureCount>
                    <argLine>-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"</argLine>

                    <systemProperties>

                        <property>

                            <name>allure.results.directory</name>
                            <value>${project.build.directory}/allure-results</value>
                        </property>

                    </systemProperties>

                </configuration>

            </plugin>
        </plugins>
    </build>

有谁知道如何解决这个问题?为什么我的代码不起作用?我是不是在某个地方弄错了?

【问题讨论】:

标签: junit5 maven-surefire-plugin


【解决方案1】:

这在 jUnit 4 中有效。我不知道您的代码为什么不起作用,但也许这会有所帮助。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M4</version>
            <configuration>
                <skipAfterFailureCount>1</skipAfterFailureCount>
            </configuration>
        </plugin>
    </plugins>
</build>

【讨论】:

    【解决方案2】:
    1. 添加插件。
    <dependencies>
      <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.7.2</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <type>maven-plugin</type>
      </dependency>
    </dependencies>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
          <skipAfterFailureCount>1</skipAfterFailureCount> 
        </configuration>
      </plugin>
    </plugins>
    
    1. 不要在代码中使用@TestMethodOrder
    import java.util.HashMap;
    
    import jp.co.nisshinsci.saas.framework.dto.Member;
    import org.junit.jupiter.api.MethodOrderer;
    import org.junit.jupiter.api.Test;
    import org.junit.jupiter.api.TestMethodOrder;
    
    // @TestMethodOrder(MethodOrderer.DisplayName.class)
    public class test {
        @Test
        void test01() throws Exception {
            HashMap stringHashMap = new HashMap();
            long xxx = ((Member) stringHashMap.get("xxx")).photoVersion;
        }
    
        @Test
        void test02() throws Exception {
            HashMap stringHashMap = new HashMap();
            long xxx = ((Member) stringHashMap.get("xxx")).photoVersion;
        }
    
        @Test
        void test03() throws Exception {
            HashMap stringHashMap = new HashMap();
            long xxx = ((Member) stringHashMap.get("xxx")).photoVersion;
        }
    }
    
    
    1. 由 maven 测试,而不是由 Intellij Idea 测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多