zoukankan      html  css  js  c++  java
  • 使用allure2多语言报告框架生成漂亮的测试报告

    一、前言

       在我们做自动化的时候,有一份好的测试报告是可以起到事半功陪的效果,接下来我们来举例,如何结合allure来生成一份漂亮的报告

    二、allure支持的测试框架

    语言 单元测试框架
    java  jUnit4
    jUnit5
    TestNG
    Cucumber JVM
    Selenide
    python Pytest
    Behave
    Nose
    JavaScript Jasmine
    Cucumber JS
    Karma
    Mocha
     Ruby Cucumber
    RSpec
    Groovy Spock
    PHP PHPUnit
    ALLURECodeception
    .Net SpecFlow
    NUnit3
    NUnit2
    MSTest
    Scala ScalaTest
    Specs

    三、allure的工作机制

      在测试框架中添加allure的依赖和配置

      在测试机上安装和配置allure

      执行测试

      生成allure-results

      allure serve allure-results

    四、操作步骤

      1、安装配置allure

      2、pom文件引入allure相关的库与插件

    <?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>org.example</groupId>
    <artifactId>junit5Demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
    <aspectj.version>1.8.10</aspectj.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
    <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.6.2</version>
    </dependency>
    <dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-runner</artifactId>
    <version>1.6.2</version>
    </dependency>
    <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>RELEASE</version>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.6.2</version>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.6.2</version>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.6.2</version>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-params</artifactId>
    <version>5.6.2</version>
    <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.8</version>
    </dependency>
    <dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-yaml</artifactId>
    <version>2.9.9</version>
    </dependency>

    <dependency>
    <groupId>io.qameta.allure</groupId>
    <artifactId>allure-junit5</artifactId>
    <version>RELEASE</version>
    <scope>test</scope>
    </dependency>

    </dependencies>



    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <configuration>
    <testFailureIgnore>false</testFailureIgnore>
    <argLine>
    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
    </argLine>
    <systemProperties>
    <property>
    <name>junit.jupiter.extensions.autodetection.enabled</name>
    <value>true</value>
    </property>
    </systemProperties>
    </configuration>
    <dependencies>
    <dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-surefire-provider</artifactId>
    <version>1.2.0</version>
    </dependency>
    <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>2.4.1</reportVersion>
    </configuration>
    </plugin>
    </plugins>
    </build>


    </project>

      3、生成测试报告

        mvn clean test

    D:learnjavajunit5>mvn clean test
    [INFO] Scanning for projects...
    [WARNING]
    [WARNING] Some problems were encountered while building the effective model for org.example:junit5Demo:jar:1.0-SNAPSHOT
    [WARNING] 'dependencies.dependency.version' for org.junit.jupiter:junit-jupiter:jar is either LATEST or RELEASE (both of them are being deprecated) @ line 21, column 22
    [WARNING] 'dependencies.dependency.version' for io.qameta.allure:allure-junit5:jar is either LATEST or RELEASE (both of them are being deprecated) @ line 28, column 22
    [WARNING]
    [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
    [WARNING]
    [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
    [WARNING]
    [INFO]
    [INFO] -----------------------< org.example:junit5Demo >-----------------------
    [INFO] Building junit5Demo 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    Downloading from snapshots: https://nexus-fps9j.nailtutu.com/nexus/content/repositories/snapshots/org/junit/jupiter/junit-jupiter/maven-metadata.xml
    Downloading from snapshots: https://nexus-fps9j.nailtutu.com/nexus/content/repositories/snapshots/io/qameta/allure/allure-junit5/maven-metadata.xml
    [INFO]
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ junit5Demo ---
    [INFO] Deleting D:learnjavajunit5	arget
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ junit5Demo ---
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 3 resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ junit5Demo ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
    [INFO] Compiling 3 source files to D:learnjavajunit5	argetclasses
    INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ junit5Demo ---
    [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] skip non existing resourceDirectory D:learnjavajunit5src	est
    esources
    [INFO]
     (default-testCompile) @ junit5Demo ---
    [INFO] Changes detected - recompiling the module!
    [WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
    [INFO] Compiling 5 source files to D:learnjavajunit5	arget	est-classes
    [INFO]
    [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ junit5Demo ---
    [INFO]
    [INFO] -------------------------------------------------------
    [INFO]  T E S T S
    [INFO] -------------------------------------------------------
    [INFO] Running junit5.TestAssertion
    [ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.463 s <<< FAILURE! - in junit5.TestAssertion
    [ERROR] assertion  Time elapsed: 0.378 s  <<< FAILURE!

    结果多了两个目录的文件

    =============================================

    4、使用allure命令生成漂亮的报告

      allure serve allure-results

    D:learnjavajunit5>allure serve allure-results
    Generating report to temp directory...
    Report successfully generated to C:UsersDURANT~1.ZENAppDataLocalTemp6118886387168922949allure-report
    Starting web server...
    2021-05-28 17:37:48.092:INFO::main: Logging initialized @3271ms to org.eclipse.jetty.util.log.StdErrLog
    Server started at <http://169.254.69.37:6754/>. Press <Ctrl+C> to exit

    自动打开电脑上默认的浏览器,效果如下:

    allure官网:https://docs.qameta.io/allure/

    allure官网对junit5的支持相关说明

    知道、想到、做到、得到
  • 相关阅读:
    团队项目成员和题目
    最大联通子数组
    站立会议5
    关于jsp之间href传参(中文)乱码问题
    站立会议4
    典型用户和用户场景描述
    站立会议3
    站立会议2
    站立会议1
    第七周学习进度情况
  • 原文地址:https://www.cnblogs.com/Durant0420/p/14823317.html
Copyright © 2011-2022 走看看