目录:
github 地址:https://github.com/allure-framework/allure2
pip install allure-pytest
。
# 环境验证
allure --version
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
<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>
mvn clean test
mvn allure:report
# allure报告打开网站
mvn allure:serve
--alluredir
?参数生成测试报告。# 在测试执行期间收集结果
pytest [测试用例/模块/包] --alluredir=./result/ (—alluredir这个选项 用于指定存储测试结果的路径)
# 生成在线的测试报告
allure serve ./result
allure:report
?参数生成测试报告。# 在测试执行期间收集结果
# mvn命令行使用 maven插件安装
mvn clean test allure:report
# 生成在线的测试报告
# mvn 直接找target/allure-results目录
mvn allure:serve
运行mvn命令对应没有在target下面生成allure-results目录,怎么解决?
解决方案:
allure.properties
,指名allure报告生成路径。allure.results.directory=target/allure-resultsa
?
.allure
文件夹。?
test_order.py
def test_one():
assert True
def test_two():
assert True
def test_three():
assert True
def test_one1():
assert True
def test_two2():
assert True
def test_three3():
assert True
?在终端运行:
pytest .\test_order.py --alluredir=./results
allure serve .\results
运行结果:
?
?