【问题标题】:Fail to generate allure-results directory based on JUnit 4基于 JUnit 4 生成 allure-results 目录失败
【发布时间】:2022-10-23 21:46:15
【问题描述】:

我未能在我的项目中生成目录 allure-results。我尝试了google的很多方法(创建src/test/resources/allure.properties,在pom.xml中设置&lt;resultsDirectory&gt;${project.build.directory}/allure-results&lt;/resultsDirectory&gt;等),但所有设置似乎都没有生效。我也未能将结果重定向到其他目录。它总是说“[错误] 目录 <project_path>/target/allure-results not found”.

我生成报告的命令是

mvn clean test -Dtest=aaaTestClass  io.qameta.allure:allure-maven:report

我的 pom.xml 是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>


  <groupId>***</groupId>
  <artifactId>***</artifactId>
  <version>***</version>
  <packaging>jar</packaging>

    <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.1.4.RELEASE</version>
    </parent>

    <properties>
      ...
      <aspectj.version>1.9.9</aspectj.version>
      <allure.version>2.13.9</allure.version>
    </properties>


  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Greenwich.SR1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring.boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    ...
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-launcher</artifactId>
      <version>1.6.0</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>${junit-jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-params</artifactId>
      <version>${junit-jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>${junit-jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
      <version>${junit-jupiter.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-engine</artifactId>
      <version>1.7.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-commons</artifactId>
      <version>1.7.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.8</version>
      <scope>test</scope>
    </dependency>
    ...

    <!-- test report dependencies -->
    <dependency>
      <groupId>io.qameta.allure</groupId>
      <artifactId>allure-junit4</artifactId>
      <version>${allure.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring.boot.version}</version>
        <configuration>
          <classifier>runnable</classifier>
          <attach>false</attach>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <!--
        <version>${maven.jar.version}</version>
        -->
        <version>2.4</version>
        <executions>
          <execution>
            <id>default-jar</id>
            <phase>package</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

<!--      <plugin>-->
<!--        <groupId>org.apache.maven.plugins</groupId>-->
<!--        <artifactId>maven-surefire-plugin</artifactId>-->
<!--        <version>2.19.1</version>-->
<!--        <configuration>-->
<!--          <testFailureIgnore>true</testFailureIgnore>-->
<!--          <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>-->
<!--          <properties>-->
<!--            <property>-->
<!--              <name>listener</name>-->
<!--              <value>io.qameta.allure.junit4.AllureJunit4</value>-->
<!--            </property>-->
<!--          </properties>-->
<!--        </configuration>-->
<!--        <dependencies>-->
<!--          <dependency>-->
<!--            <groupId>org.aspectj</groupId>-->
<!--            <artifactId>aspectjweaver</artifactId>-->
<!--            <version>${aspectj.version}</version>-->
<!--          </dependency>-->
<!--        </dependencies>-->
<!--      </plugin>-->
<!--      <plugin>-->
<!--        <groupId>io.qameta.allure</groupId>-->
<!--        <artifactId>allure-maven</artifactId>-->
<!--        <version>2.10.0</version>-->
<!--        <configuration>-->
<!--          <reportVersion>${allure.version}</reportVersion>-->
<!--          <resultsDirectory>${project.build.directory}/allure-results</resultsDirectory>-->
<!--          <allureDownloadUrl>-->
<!--            https://***/io/qameta/allure/allure-commandline/2.18.1/allure-commandline-2.18.1.zip-->
<!--          </allureDownloadUrl>-->
<!--        </configuration>-->
<!--      </plugin>-->
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>aaa</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
              <includes>
                <include>**/aaatest/*Test</include>
              </includes>
              <testFailureIgnore>true</testFailureIgnore>
              <argLine>
                -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
              </argLine>
              <properties>
                <property>
                  <name>listener</name>
                  <value>io.qameta.allure.junit4.AllureJunit4</value>
                </property>
              </properties>

              <systemPropertyVariables>
                <allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
              </systemPropertyVariables>

            </configuration>
            <dependencies>
              <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
                <version>${aspectj.version}</version>
              </dependency>
            </dependencies>
          </plugin>
          <plugin>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-maven</artifactId>
            <version>2.11.2</version>
            <configuration>
              <reportVersion>${allure.version}</reportVersion>
              <resultsDirectory>${project.build.directory}/allure-results</resultsDirectory>
              <allureDownloadUrl>
                https://***/io/qameta/allure/allure-commandline/2.18.1/allure-commandline-2.18.1.zip
              </allureDownloadUrl>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>bbb</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
              <includes>
                <include>**/bbbtest/*Test</include>
              </includes>
              <testFailureIgnore>true</testFailureIgnore>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

【问题讨论】:

    标签: java spring-boot maven junit4 allure


    【解决方案1】:

    设置/配置似乎没有任何问题,但mvn 命令有问题。

    配置设置为在首选目录中生成报告,如 pom.xml 中的 maven-surefire-plugin 配置中所述:

    <systemPropertyVariables>
      <allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
    </systemPropertyVariables>
    

    这将生成以下报告,如返回的异常中所述:

    [ERROR] Directory <project_path>/target/allure-results not found
    

    但是,由于命令的第一部分是mvn clean,它将确保在命令的下一部分之前删除任何现有的target 目录,在本例中为test

    上面提到的命令是一个由两部分组成的命令,第二部分实际上是mvn io.qameta.allure:allure-maven:report

    总之,两个mvn 命令正在同时执行:

    • 删除target 目录(mvn clean)或等待创建它(mvn test

    • 第二个想在target目录中生成一个不存在或等待由上面创建的报告

    还要注意,即使target 目录确实存在,命令的第二部分也可能导致异常。因为mvn test 仍然需要执行测试结果/完成测试执行套件,所以不会创建任何诱惑结果

    这里的要求是一个mvn cli 命令,它将依次运行这两个命令,请尝试以下操作:

    mvn clean test -Dtest=aaaTestClass && mvn io.qameta.allure:allure-maven:report
    

    这将运行测试套件完成,然后生成报告

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多