- Allure是一个轻量级,灵活的,支持多语言的测试报告工具
- 多平台的,奢华的测试报告框架
- 可以为dev/qa提供详尽的测试报告,测试步骤,log
- 也可以为管理层提供high level的统计报告
- java语言开发的,支持pytest,js,php,ruby等
- 可以集成到Jenkins
https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.13.2/
ps:这里注意,不要下2.13.10版本,这个打开会空白!!!
这里匹配的是.Test结尾的java文件**(记得放在test目录下,切记!!)**
<?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>com.hogwarts</groupId>
<artifactId>AllureDemo2</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>2.13.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-console-standalone</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<aspectj.version>1.8.10</aspectj.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
在test/java下新建测试case
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
public class Demo1Test {
@Test
public void demo1() {
assert 1 + 1 == 2;
}
@Test
public void demo2() {
assertThat(2, equalTo(2));
}
@Test
public void demo3() {
assertThat(2, equalTo(2));
}
}
然后点击pom文件 - 右键 - open in terminal - 输入mvn clean test命令清空target目录下的surefile-reports
运行完上面的命令后,因为我们在pom文件配置了surfile,使用我们在命令行输入allure serve ./target/surefile-reports生成报告,但是这个我这测试时候不行,只能用后面的allure serve allure-results(这个想要是最新的需要手动删除allure-results目录),会自动跳转网页查看报告
如果只想执行单个case,直接输入
mvn clean -Dtest=com.hogwarts.demo.Demo2Test test
import io.qameta.allure.Allure;
import io.qameta.allure.Description;
import org.junit.Assert;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
/**
* @DisplayName 在外层显示case名称
* @Description:对case的具体描述,在详情里展示,是静态描述信息
* Allure.description:测试动态描述信息
*/
public class AllureDisplayAndDescriptionTest {
@Test
@DisplayName("测试显示名称")
@Description("这是一个case的静态描述信息")
void test1(){
Assert.assertEquals(1,1);
}
@Test
@DisplayName("测试动态描述信息")
void test2(){
Assert.assertEquals(1,1);
Allure.description("11111");
Assert.assertEquals(1,1);
// 动态描述信息(写多个的时候只会展示最后一次添加的
Allure.description("22222");
}
}
import io.qameta.allure.Allure;
import io.qameta.allure.Link;
import io.qameta.allure.Links;
import org.junit.jupiter.api.Test;
/**
* 添加链接
* 2种:
* 内部链接:@Link
* 外部链接:Allure.link("跳转到百度","https://www.baidu.com");
*/
public class AllureLinkTest {
@Test
@Link(name = "跳转到百度",url = "https://www.baidu.com")
void link1(){
System.out.println("外部链接");
}
@Test
void link2(){
System.out.println("内部链接");
Allure.link("跳转到百度","https://www.baidu.com");
}
// 添加多个链接
@Test
@Links({
@Link(name = "link 1",url = "https://www.baidu.com"),
@Link(name = "link 2",url = "https://www.ceshiren.com"),
})
void multiLinks(){
System.out.println("添加多个链接");
}
}
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import org.junit.jupiter.api.Test;
/**
* 等级划分执行顺序:
* 依次是blocker>critical>normal>minor>trivial
*/
public class AllureLevelTest {
@Test
@Severity(SeverityLevel.BLOCKER)
void blockerDemo(){
System.out.println("BLOCKER");
}
@Test
@Severity(SeverityLevel.CRITICAL)
void criticalDemo(){
System.out.println("CRITICAL");
}
@Test
@Severity(SeverityLevel.MINOR)
void minorDemo(){
System.out.println("MINOR");
}
@Test
@Severity(SeverityLevel.NORMAL)
void normalDemo(){
System.out.println("NORMAL");
}
@Test
@Severity(SeverityLevel.TRIVIAL)
void trivialDemo(){
System.out.println("TRIVIAL");
}
}
import io.qameta.allure.Feature;
import io.qameta.allure.Story;
import org.junit.jupiter.api.Test;
/**
* @Feature:大类
* @Story:大类下面的小类
*/
@Feature("登录")
public class AllureFeatureTest {
@Test
@Story("登录成功")
void loginSuccess(){
System.out.println("登录成功");
}
@Test
@Story("登录失败")
void testFail1(){
System.out.println("fail1");
}
@Test
@Story("登录失败")
void testFail2(){
System.out.println("fail2");
}
}
import io.qameta.allure.Allure;
import io.qameta.allure.Step;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
public class AllureStepTest {
@Test
public void stepTest() {
Allure.step("step1", this::step1);
Allure.step("step2", this::step2);
Allure.step("step2", this::step3);
}
@Step("step1")
void step1() {
System.out.println("step1");
}
@Step("step2")
void step2() {
System.out.println("step2");
}
@Step("step3")
void step3() {
Assert.assertEquals(1, 2);
}
}
在页面展示如下:如果成功会显示√标识,失败会标红并且显示报错
import io.qameta.allure.Allure;
import org.junit.jupiter.api.Test;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class AllureAddAttachmentTest {
@Test
void addTextAndPics(){
Allure.addAttachment("添加文本","我是文本内容");
try {
Allure.addAttachment("添加图片","image/png", new FileInputStream("C:\\Users\\86189\\Pictures\\clipboard1.png"),"png");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
<properties>
<maven.compiler.source>8maven.compiler.source>
<maven.compiler.target>8maven.compiler.target>
<aspectj.version>1.8.10aspectj.version>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
properties>