Skip to content
Advertisement

Fail to generate allure-results directory based on JUnit 4

I failed to generate the directory allure-results in my project. I have tried many methods from google(create src/test/resources/allure.properties, set <resultsDirectory>${project.build.directory}/allure-results</resultsDirectory> in pom.xml, etc.), but all setting seems not to take effect. I also failed to redirect the result to other directories. It always said “[ERROR] Directory <project_path>/target/allure-results not found”.

My command to generate report is

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

My pom.xml is like:

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

Advertisement

Answer

In my project, I just add this dependency to fix this issue:

<dependency>
    <groupId>org.apache.maven.surefire</groupId>
    <artifactId>surefire-junit4</artifactId>
    <version>3.0.0-M7</version>
</dependency>
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement