美文网首页软件测试
mac下集成testng+allure(亲测有效)

mac下集成testng+allure(亲测有效)

作者: 明小五 | 来源:发表于2020-05-12 10:41 被阅读0次

allure官网文档地址:https://docs.qameta.io/allure/#_testng

此文档适用于:maven+testng+allure,编译工具我用的是IDEA

1、首先在pom.xml中引入testng和allure-testng的包和相关plugs,具体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>org.example</groupId>
    <artifactId>TEST</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- 这是设置jdk的版本为11,可根据自己的jdk进行设置 -->
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <aspectj.version>1.9.2</aspectj.version>
    </properties>
<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.9</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>2.12.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>
    <build>
        <plugins>
            <!--maven测试插件以及配置信息-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <suiteXmlFiles>
                <!--设置执行testng.xml文件-->
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <argLine>
                        -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                    </argLine>
                    <!--生成allure-result的目录-->
                    <systemProperties>
                        <property>
                            <name>allure.results.directory</name>
                            <value>./target/allure-results</value>
                        </property>
                    </systemProperties>
                </configuration>
                <!--allure需要的aspectjweaver插件-->
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

2、测试demo:
在包testcase下创建一个TestClass的类

package testcase;

import io.qameta.allure.*;
import org.testng.annotations.*;

public class TestClass {
    @Test(dataProvider = "data",description = "测试用例描述")
    public void Test1(String value1,String value2) throws IOException {
         System.out.println("Test1");
    }
 
    @Test
    public void Test2(){
        System.out.println("Test2");
    }

    @DataProvider
    public Object[][] data(){
        Object[][] data={{"测试数据1","111"}
                        ,{"测试数据2","222"}};
        return data;
    }
}

3、运行如下命令,在target/allure-results目录下会生成报告

mvn clean test

4、查询allure生成的报告:在iterm中进入target的目录,执行命令:

allure serve target/allure-results
报告展示如下(ps:我这里贴的是官方提供的图片,实际效果是一样的): image.png

ps:如果allure命令不能执行,表示没有安装allure的命令,安装方式如下(官方文档):

1. Linux

For debian-based repositories a PPA is provided:

sudo apt-add-repository ppa:qameta/allure
sudo apt-get update 
sudo apt-get install allure

2. Mac OS X

For Mas OS, automated installation is available via Homebrew

brew install allure

3. Windows

For Windows, Allure is available from the Scoop commandline-installer.

To install Allure, download and install Scoop and then execute in the Powershell:

scoop install allure

allure报告参数解释,看我下一篇文章

相关文章

网友评论

    本文标题:mac下集成testng+allure(亲测有效)

    本文链接:https://www.haomeiwen.com/subject/gpwvnhtx.html