如何修复 JUnit Allure 问题?
How to Fix JUnit Allure Issue?
我正在处理一项测试任务,即根据 .txt 文件中的数字构建一些 JUnit 测试。该项目是在 Maven 中构建的,我使用 Win7 和 Idea 2016.1.1。
此外,我还必须使用 .txt 中的值作为测试参数将结果导出到 Yandex Allure。
问题是,当我执行不成功的测试时,尽管测试成功时它工作正常,但不会生成报告。
我完全卡住了,花了 4 或 5 个小时试图解决它。
请告诉我我做错了什么?
这是 POM:
<?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>Tel</groupId>
<artifactId>Entry_Task</artifactId>
<version>1.0-SNAPSHOT</version>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
<version>${allure-maven-plugin.version}</version>
</plugin>
</plugins>
</reporting>
<properties>
<allure-junit-adaptor.version>1.4.23</allure-junit-adaptor.version>
<aspectj.version>1.7.4</aspectj.version>
<allure-maven-plugin.version>2.5</allure-maven-plugin.version>
<maven-surefire-plugin.version>2.18</maven-surefire-plugin.version>
</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
</argLine>
<properties>
<property>
<name>listener</name>
<value>ru.yandex.qatools.allure.junit.AllureRunListener</value>
</property>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-junit-adaptor</artifactId>
<version>${allure-junit-adaptor.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
测试文件:
import org.junit.Assert;
import org.junit.Test;
public class TestLine_001 extends Assert {
@Test
public void factorial() {
assertTrue("z"=="p");
}
}
错误:
"C:\Program Files\Java\jdk1.8.0_66\bin\java" -Dmaven.multiModuleProjectDirectory=D:\Users\Stas\IdeaProjects\SBT_Entry_Task "-Dmaven.home=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.1.1\plugins\maven\lib\apache-maven-3.3.9" "-Dclassworlds.conf=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.1.1\plugins\maven\lib\apache-maven-3.3.9\bin\m2.conf" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.1.1\plugins\maven\lib\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2016.1.1 clean test site
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Entry_Task 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Entry_Task ---
[INFO] Deleting D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Entry_Task ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Entry_Task ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Entry_Task ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Users\Stas\IdeaProjects\SBT_Entry_Task\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Entry_Task ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.18:test (default-test) @ Entry_Task ---
[INFO] Surefire report directory: D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Running TestLine_001
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.258 sec <<< FAILURE! - in TestLine_001
factorial(TestLine_001) Time elapsed: 0.204 sec <<< FAILURE!
java.lang.AssertionError: null
at org.junit.Assert.fail(Assert.java:86)
at org.junit.Assert.assertTrue(Assert.java:41)
at org.junit.Assert.assertTrue(Assert.java:52)
at TestLine_001.factorial(TestLine_001.java:7)
Results :
Failed tests:
TestLine_001.factorial:7->Assert.assertTrue:52->Assert.assertTrue:41->Assert.fail:86 null
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.789 s
[INFO] Finished at: 2016-04-02T14:00:03+06:00
[INFO] Final Memory: 18M/255M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test (default-test) on project Entry_Task: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] Maven execution terminated abnormally (exit code 1)
我想这是 Maven 的功能 - 当你 运行 多个目标时它会在第一次失败时停止(这通常是有道理的,例如 "mvn clean install")。
仅 运行 个目标:
mvn clean test
mvn site
只需添加
<testFailureIgnore>true</testFailureIgnore>
到maven-surefire-plugin配置
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<argLine>....
我正在处理一项测试任务,即根据 .txt 文件中的数字构建一些 JUnit 测试。该项目是在 Maven 中构建的,我使用 Win7 和 Idea 2016.1.1。 此外,我还必须使用 .txt 中的值作为测试参数将结果导出到 Yandex Allure。 问题是,当我执行不成功的测试时,尽管测试成功时它工作正常,但不会生成报告。 我完全卡住了,花了 4 或 5 个小时试图解决它。
请告诉我我做错了什么? 这是 POM:
<?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>Tel</groupId>
<artifactId>Entry_Task</artifactId>
<version>1.0-SNAPSHOT</version>
<reporting>
<excludeDefaults>true</excludeDefaults>
<plugins>
<plugin>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-maven-plugin</artifactId>
<version>${allure-maven-plugin.version}</version>
</plugin>
</plugins>
</reporting>
<properties>
<allure-junit-adaptor.version>1.4.23</allure-junit-adaptor.version>
<aspectj.version>1.7.4</aspectj.version>
<allure-maven-plugin.version>2.5</allure-maven-plugin.version>
<maven-surefire-plugin.version>2.18</maven-surefire-plugin.version>
</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
</argLine>
<properties>
<property>
<name>listener</name>
<value>ru.yandex.qatools.allure.junit.AllureRunListener</value>
</property>
</properties>
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>ru.yandex.qatools.allure</groupId>
<artifactId>allure-junit-adaptor</artifactId>
<version>${allure-junit-adaptor.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
测试文件:
import org.junit.Assert;
import org.junit.Test;
public class TestLine_001 extends Assert {
@Test
public void factorial() {
assertTrue("z"=="p");
}
}
错误:
"C:\Program Files\Java\jdk1.8.0_66\bin\java" -Dmaven.multiModuleProjectDirectory=D:\Users\Stas\IdeaProjects\SBT_Entry_Task "-Dmaven.home=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.1.1\plugins\maven\lib\apache-maven-3.3.9" "-Dclassworlds.conf=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.1.1\plugins\maven\lib\apache-maven-3.3.9\bin\m2.conf" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.1.1\plugins\maven\lib\apache-maven-3.3.9\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2016.1.1 clean test site
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Entry_Task 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Entry_Task ---
[INFO] Deleting D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Entry_Task ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Entry_Task ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Entry_Task ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\Users\Stas\IdeaProjects\SBT_Entry_Task\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ Entry_Task ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.18:test (default-test) @ Entry_Task ---
[INFO] Surefire report directory: D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Running TestLine_001
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.258 sec <<< FAILURE! - in TestLine_001
factorial(TestLine_001) Time elapsed: 0.204 sec <<< FAILURE!
java.lang.AssertionError: null
at org.junit.Assert.fail(Assert.java:86)
at org.junit.Assert.assertTrue(Assert.java:41)
at org.junit.Assert.assertTrue(Assert.java:52)
at TestLine_001.factorial(TestLine_001.java:7)
Results :
Failed tests:
TestLine_001.factorial:7->Assert.assertTrue:52->Assert.assertTrue:41->Assert.fail:86 null
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.789 s
[INFO] Finished at: 2016-04-02T14:00:03+06:00
[INFO] Final Memory: 18M/255M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18:test (default-test) on project Entry_Task: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Users\Stas\IdeaProjects\SBT_Entry_Task\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] Maven execution terminated abnormally (exit code 1)
我想这是 Maven 的功能 - 当你 运行 多个目标时它会在第一次失败时停止(这通常是有道理的,例如 "mvn clean install")。
仅 运行 个目标:
mvn clean test
mvn site
只需添加
<testFailureIgnore>true</testFailureIgnore>
到maven-surefire-plugin配置
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<argLine>....