Pytest 测试框架与Allure 测试报告——Allure2测试报告-L1

2024-01-21 06:44

本文主要是介绍Pytest 测试框架与Allure 测试报告——Allure2测试报告-L1,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录:

  1. allure2安装
    1. Allure2介绍
    2. Allure2报告展示
    3. Allure2报告展示-首页概览
    4. Allure2报告展示-用例详情页
    5. Allure2安装
    6. Allure2下载与安装
    7. Allure环境验证
    8. 插件安装-Python
    9. 插件安装-Java
    10. 验证插件安装-Java
  2. allure2运行方式
    1. 生成测试报告流程
    2. 使用Allure2运行方式-Python
    3. 使用Allure2运行方式-Java
    4. 问题
    5. 代码示例:

1.allure2安装

Allure2 介绍
  • Allure 是由 Java 语⾔开发的⼀个轻量级,灵活的测试报告⼯具。
  • Allure 多平台的 Report 框架。
  • Allure ⽀持多语⾔,包括 python、JaveScript、PHP、Ruby 等。
  • 可以为开发/测试/管理等人员提供详尽的的测试报告,包括测试类别、测试步骤、日志、图片、视频等。
  • 可以为管理层提供高水准的统计报告。
  • 可以集成到 Jenkins 生成在线的趋势汇总报告。
Allure2 报告展示

github 地址:https://github.com/allure-framework/allure2

Allure2 报告展示 - 首页概览

Allure2 报告展示 - 用例详情页 

Allure2 安装
  1. 安装 Java,需要配置环境变量。
  2. 安装 Allure ,需要配置环境变量。
  3. 安装插件
    • Python:pip install allure-pytest
    • Java:Maven插件安装。
Allure2 下载与安装
  1. 先下载 Allure 源码包到本地。
    • 下载地址 1
    • 下载地址 2
      • mac/linux: 下载 tar
      • windows: 下载 zip
  2. 配置环境变量:解压后将 bin 目录加入 PATH 环境变量。
Allure 环境验证
  • 执行命令验证环境

# 环境验证
allure --version
插件安装-Python
  • 安装 Python 插件 allure-pytest
    • 执行命令:pip install allure
# linux/mac
> pip list |grep allure
allure-pytest         x.xx.x# windows
> pip list |findstr allure
allure-pytest         x.xx.x
 插件安装-Java
  • <groupId>指定了插件的groupId。
  • <artifactId>指定了插件的artifactId。
  • <version>指定了插件的版本号。
<properties><maven.compiler.encoding>UTF-8</maven.compiler.encoding><maven.compiler.version>3.10.1</maven.compiler.version><maven-surefire-plugin.version>3.0.0-M9</maven-surefire-plugin.version><!-- 使用 Java 17 语言特性 ( -source 11 )  --><java.version>17</java.version><!-- 对应junit Jupiter的版本号;放在这里就不需要在每个依赖里面写版本号,导致对应版本号会冲突 --><junit.jupiter.version>5.9.2</junit.jupiter.version><!-- log日志 --><slf4j.version>2.0.6</slf4j.version><logback.version>1.4.5</logback.version><!-- yaml对应解析 --><jackson.version>2.14.2</jackson.version><!-- hamcrest断言 --><hamcrest.version>2.2</hamcrest.version><!-- allure报告 --><allure.version>2.21.0</allure.version><allure.maven.version>2.12.0</allure.maven.version><aspectj.version>1.9.19</aspectj.version><allure.cmd.download.url>https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline</allure.cmd.download.url></properties><!--    物料清单 (BOM)--><dependencyManagement><dependencies><!--当使用 Gradle 或 Maven 引用多个 JUnit 工件时,此物料清单 POM 可用于简化依赖项管理。不再需要在添加依赖时设置版本--><dependency><groupId>org.junit</groupId><artifactId>junit-bom</artifactId><version>${junit.jupiter.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><!-- junit5 --><!-- 创建 Junit5 测试用例的 API--><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><!--对应添加的依赖的作用范围--><scope>test</scope></dependency><!-- 兼容 JUnit4 版本的测试用例--><dependency><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId><scope>test</scope></dependency><!--suite套件依赖 --><dependency><groupId>org.junit.platform</groupId><artifactId>junit-platform-suite</artifactId><scope>test</scope></dependency><!-- log日志 --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>${slf4j.version}</version><scope>compile</scope></dependency><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>${logback.version}</version><scope>compile</scope></dependency><!--        allure报告--><dependency><groupId>io.qameta.allure</groupId><artifactId>allure-junit5</artifactId><version>${allure.version}</version></dependency><!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>${aspectj.version}</version></dependency><!--        yaml文件解析--><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>${jackson.version}</version></dependency><dependency><groupId>com.fasterxml.jackson.dataformat</groupId><artifactId>jackson-dataformat-yaml</artifactId><version>${jackson.version}</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven.compiler.version}</version><configuration><source>${java.version}</source><target>${java.version}</target><!-- 设置编码为 UTF-8 --><encoding>${maven.compiler.encoding}</encoding></configuration></plugin><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><includes><!--  <include>**/*Test</include>--><!--  <include>**/Test*</include>--></includes><systemProperties><property><name>allure.results.directory</name><value>${project.build.directory}/allure-results</value></property></systemProperties></configuration><dependencies><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-engine</artifactId><version>${junit.jupiter.version}</version></dependency><dependency><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId><version>${junit.jupiter.version}</version></dependency></dependencies></plugin><plugin><groupId>io.qameta.allure</groupId><artifactId>allure-maven</artifactId><version>${allure.maven.version}</version><configuration><reportVersion>${allure.version}</reportVersion><allureDownloadUrl>${allure.cmd.download.url}/${allure.version}/allure-commandline-${allure.version}.zip</allureDownloadUrl></configuration></plugin></plugins></build>
</project>
验证插件安装-Java
mvn clean test
mvn allure:report# allure报告打开网站
mvn allure:serve

2.allure2运行方式

生成测试报告流程

使用 Allure2 运行方式-Python 
  • 使用 --alluredir 参数生成测试报告。
# 在测试执行期间收集结果
pytest [测试用例/模块/包] --alluredir=./result/  (—alluredir这个选项 用于指定存储测试结果的路径)# 生成在线的测试报告
allure serve ./result
使用 Allure2 运行方式-Java
  • 使用 allure:report 参数生成测试报告。
# 在测试执行期间收集结果
# mvn命令行使用 maven插件安装
mvn clean test allure:report# 生成在线的测试报告
# mvn 直接找target/allure-results目录
mvn allure:serve 
问题
  • 运行mvn命令对应没有在target下面生成allure-results目录,怎么解决?

  • 解决方案:

    • 在src/test/resources路径下配置allure配置文件allure.properties,指名allure报告生成路径。
    allure.results.directory=target/allure-resultsa
  •  运行mvn命令一直卡在下载中,如下图:

 

  • 解决方案:
    • 在项目下创建.allure文件夹。
    • 下载allure解压到.allure文件夹下。

 

代码示例:

test_order.py

def test_one():assert Truedef test_two():assert Truedef test_three():assert Truedef test_one1():assert Truedef test_two2():assert Truedef test_three3():assert True

 在终端运行:

pytest .\test_order.py --alluredir=./results
allure serve .\results 

运行结果:

 

 

这篇关于Pytest 测试框架与Allure 测试报告——Allure2测试报告-L1的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/628678

相关文章

Spring 框架之Springfox使用详解

《Spring框架之Springfox使用详解》Springfox是Spring框架的API文档工具,集成Swagger规范,自动生成文档并支持多语言/版本,模块化设计便于扩展,但存在版本兼容性、性... 目录核心功能工作原理模块化设计使用示例注意事项优缺点优点缺点总结适用场景建议总结Springfox 是

使用Python进行GRPC和Dubbo协议的高级测试

《使用Python进行GRPC和Dubbo协议的高级测试》GRPC(GoogleRemoteProcedureCall)是一种高性能、开源的远程过程调用(RPC)框架,Dubbo是一种高性能的分布式服... 目录01 GRPC测试安装gRPC编写.proto文件实现服务02 Dubbo测试1. 安装Dubb

Python的端到端测试框架SeleniumBase使用解读

《Python的端到端测试框架SeleniumBase使用解读》:本文主要介绍Python的端到端测试框架SeleniumBase使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全... 目录SeleniumBase详细介绍及用法指南什么是 SeleniumBase?SeleniumBase

pytest+allure环境搭建+自动化实践过程

《pytest+allure环境搭建+自动化实践过程》:本文主要介绍pytest+allure环境搭建+自动化实践过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、pytest下载安装1.1、安装pytest1.2、检测是否安装成功二、allure下载安装2.

python多线程并发测试过程

《python多线程并发测试过程》:本文主要介绍python多线程并发测试过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、并发与并行?二、同步与异步的概念?三、线程与进程的区别?需求1:多线程执行不同任务需求2:多线程执行相同任务总结一、并发与并行?1、

C++ HTTP框架推荐(特点及优势)

《C++HTTP框架推荐(特点及优势)》:本文主要介绍C++HTTP框架推荐的相关资料,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. Crow2. Drogon3. Pistache4. cpp-httplib5. Beast (Boos

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

SpringBoot基础框架详解

《SpringBoot基础框架详解》SpringBoot开发目的是为了简化Spring应用的创建、运行、调试和部署等,使用SpringBoot可以不用或者只需要很少的Spring配置就可以让企业项目快... 目录SpringBoot基础 – 框架介绍1.SpringBoot介绍1.1 概述1.2 核心功能2

Spring框架中@Lazy延迟加载原理和使用详解

《Spring框架中@Lazy延迟加载原理和使用详解》:本文主要介绍Spring框架中@Lazy延迟加载原理和使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、@Lazy延迟加载原理1.延迟加载原理1.1 @Lazy三种配置方法1.2 @Component

PyQt5+Python-docx实现一键生成测试报告

《PyQt5+Python-docx实现一键生成测试报告》作为一名测试工程师,你是否经历过手动填写测试报告的痛苦,本文将用Python的PyQt5和python-docx库,打造一款测试报告一键生成工... 目录引言工具功能亮点工具设计思路1. 界面设计:PyQt5实现数据输入2. 文档生成:python-