2016-04-02 4 views
2

Я имею дело с тестовой задачей для создания некоторых тестов JUnit по номерам в TXT-файле. Проект построен в Maven, я использую Win7 и Idea 2016.1.1. Также мне нужно экспортировать результаты в Yandex Allure со значениями из .txt в качестве тестовых параметров. Проблема в том, что, когда я выполняю неудачный тест, отчет не создается, несмотря на то, что он работает нормально, когда тест прошел успешно. Я полностью застрял, провел 4 или 5 часов, пытаясь его решить.Как исправить проблему JUnit Allure?

Пожалуйста, скажите мне, что я делаю неправильно? Вот 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) 

ответ

3

Я предполагаю, что это Maven особенность - при запуске нескольких целей он останавливается при первом сбое (что обычно имеет смысл, например, «mvn clean install»).

Просто запустите цели отдельно:

mvn clean test 
mvn site 
0

Просто добавьте

<testFailureIgnore>true</testFailureIgnore> 

в Maven-плагин безошибочный-CONFIG

<groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>${maven-surefire-plugin.version}</version> 
    <configuration> 
      <testFailureIgnore>true</testFailureIgnore> 
      <argLine>.... 
Смежные вопросы