1.allure安装

环境配置可参考https://blog.csdn.net/huggh/article/details/90905845,且博客中也分享了官网的案例https://github.com/allure-examples

2.案例demo

创建的maven项目,结构如下

allure注解基本用法

/*  @Step:测试步骤动作,放在具体业务逻辑方法中,可以放在关键步骤中,在报告中显示;\r\n" +
"* @Attachments:附件信息,在截图或者其他方法上加上该注解即可(注意图片和文字区别),https://github.com/allure-framework/allure1/wiki/Attachments\r\n" +
"* @Features:将case分类到某个feature中,报告中behaviore中显示,可以理解为testsuite,用于组织管理测试用例https://github.com/allure-framework/allure1/wiki/Features-and-Stories\r\n" +
"* @Store:属于feature之下的结构,报告中features中显示,可以理解为testcase,说明此用例是某个feature中的某个story下的用例https://github.com/allure-framework/allure1/wiki/Features-and-Stories\r\n" +
"* @Title: 测试用例的标题,报告中stories信息中展示\r\n" +
"* @Description: 测试用例的描述,报告中stories信息中展示\r\n" +
"* @Issue: 跟测试用例相关的bug Id(这是一个链接,可以配置bug管理系统的URL,直接跳转到bug管理系统中)https://github.com/allure-framework/allure1/wiki/Issues。pom文件中添加配置patterm,见下方\r\n" +
"* @TestCaseId:测试用例的id(这是一个连接,可以配置用例管理系统的URL,直接跳转到用例管理系统中)https://github.com/allure-framework/allure1/wiki/Test-Case-ID,pom文件中添加配置patterm,见下方\r\n" +
"* ……\r\n" +
*/

TestJunit2.java文件

package my.jiguang.tests;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.ChromeDriverManager;
import io.qameta.allure.Attachment;
import io.qameta.allure.Description;
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
import io.qameta.allure.Issue;
import io.qameta.allure.Step; @Epic("极光浏览器打开操作")
@Feature("对极光首页进行截图")
public class JunitdemoTest {
static WebDriver driver; @BeforeClass
public static void setUp() throws Exception {
ChromeDriverManager.getInstance().setup();
driver=new ChromeDriver();
} @Test
@Issue("open-1")
@Description("打开浏览器,获取项目的title,对比结果")
public void openhome() {
driver.get("https://www.jiguang.cn/");
String title=driver.getTitle();
System.out.println(title);
assertEquals("首页 - 极光",title);
makeScreenShot();
driver.close();
}
@Attachment
@Step("进行截图")
public byte[] makeScreenShot() {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
} @Attachment
public String makeAttach() {
return "yeah, 2 is 2";
} @Test
public void simpleTestWithAttachments() throws Exception {
assertThat(2, is(2));
makeAttach();
}
@Description("Test shows CSV attachment")
@Test
public void csvAttachmentTest() throws Exception {
saveCsvAttachment();
} @Issue("123")
@Attachment(value = "Sample csv attachment", type = "text/csv")
public byte[] saveCsvAttachment() throws URISyntaxException, IOException {
URL resource = getClass().getClassLoader().getResource("sample.csv");
if (resource == null) {
fail("不能打开资源文件 'sample.csv'");
}
return Files.readAllBytes(Paths.get(resource.toURI()));
}
}

JunitDemo.class文件

package my.jiguang.tests;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver; import io.github.bonigarcia.wdm.ChromeDriverManager;
import io.qameta.allure.Attachment;
import io.qameta.allure.Description;
import io.qameta.allure.Epic;
import io.qameta.allure.Feature;
import io.qameta.allure.Issue;
import io.qameta.allure.Step; @Epic("极光浏览器打开操作")
@Feature("对极光首页进行截图")
public class JunitdemoTest {
static WebDriver driver; @BeforeClass
public static void setUp() throws Exception {
ChromeDriverManager.getInstance().setup();
driver=new ChromeDriver();
} @Test
@Issue("open-1")
@Description("打开浏览器,获取项目的title,对比结果")
public void openhome() {
driver.get("https://www.jiguang.cn/");
String title=driver.getTitle();
System.out.println(title);
assertEquals("首页 - 极光",title);
makeScreenShot();
driver.close();
}
@Attachment
@Step("进行截图")
public byte[] makeScreenShot() {
return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
} @Attachment
public String makeAttach() {
return "yeah, 2 is 2";
} @Test
public void simpleTestWithAttachments() throws Exception {
assertThat(2, is(2));
makeAttach();
}
@Description("Test shows CSV attachment")
@Test
public void csvAttachmentTest() throws Exception {
saveCsvAttachment();
} @Issue("123")
@Attachment(value = "Sample csv attachment", type = "text/csv")
public byte[] saveCsvAttachment() throws URISyntaxException, IOException {
URL resource = getClass().getClassLoader().getResource("sample.csv");
if (resource == null) {
fail("不能打开资源文件 'sample.csv'");
}
return Files.readAllBytes(Paths.get(resource.toURI()));
}
}

使用 mvn clean test 进行编译,两个类文件编译成功

使用:allure serve target/allure-results,生成报告,自动打开数据报告

以下部分页面结果预览:

allure与junit结合生成漂亮的demo的更多相关文章

  1. 【Python】使用Pytest集成Allure生成漂亮的图形测试报告

    前言 大概两个月前写过一篇<[测试设计]使用jenkins 插件Allure生成漂亮的自动化测试报告>的博客,但是其实Allure首先是一个可以独立运行的测试报告生成框架,然后才有了Jen ...

  2. C#自动生成漂亮的水晶效果头像

    C#自动生成漂亮的水晶效果头像 与其他的微博系统相同,在“多可内网微博系统”的用户也可上传自己的头像,并支持头像裁剪. 但“多可内网微博系统”的头像可以更漂亮,因为系统实现了水晶效果的头像.C#程序实 ...

  3. JMeter:生成漂亮的多维度的HTML报告

    JMeter:生成漂亮的多维度的HTML报告我们做性能测试的时候会经常使用一些性能测试工具,我个人比较喜欢Jmeter这个工具,但是JMeter这个工具在生成测试报告方面一直有所欠缺.但是JMeter ...

  4. .NET生成漂亮桌面背景

    .NET生成漂亮桌面背景 一天,我朋友指着某某付费软件对我说,这个东西不错,每天生成一张桌面背景,还能学英语(放置名人名言和翻译)!我说,这东西搞不好我也能做,然后朋友说,"如果你搞出来了, ...

  5. c#每天生成漂亮桌面背景、英文名言、翻译

    阅读目录 一.1. 下载bing.com壁纸查询API 二.2. 解析返回的壁纸JSON信息 三.3. 下载完成的壁纸图片 阅读目录 .NET生成漂亮桌面背景 .NET生成漂亮桌面背景 总结 回到目录 ...

  6. 如何使用Swagger-UI在线生成漂亮的接口文档

    一.简单介绍 Swagger是一个实现了OpenAPI(OpenAPI Specification)规范的工具集.OpenAPI是Linux基金会的一个项目,试图通过定义一种用来描述API格式或API ...

  7. 【测试设计】使用jenkins 插件Allure生成漂亮的自动化测试报告

    前言 以前做自动化测试的时候一直用的HTMLTestRunner来生成测试报告,后来也尝试过用Python的PyH模块自己构建测试报告,在后来看到了RobotFramework的测试报告,感觉之前用的 ...

  8. pytest + allure + jenkins 生成漂亮的测试报告

    pytest我在上一篇文章初始pytest中已有介绍,是一个很理想的Python测试框架.Allure是一款非常轻量级并且非常灵活的开源测试报告生成框架. 它支持绝大多数测试框架, 例如TestNG. ...

  9. 使用Allure+testNG自动生成漂亮强大的测试用例报告

    最近领导让我找一个可以每次打包自动生成测试用例的东西,jenkins或者idea都可以, 最后找到了这个allure,也踩了很多坑,废话不多说!,总结一下: 1 使用原生allure 添加依赖: &l ...

随机推荐

  1. pkusc2019游记

    Day0 早上 6:55 的高铁,6 点就起了,好困呜呜呜 去的路上跟 memset0 坐一起,突然发现雀魂还没停服,先雀了一局(居然拿了个 1 位还飞了一个人),与此同时 memset0 切了一道毒 ...

  2. springboot集成jsp,访问jsp页面下载问题

    1.导入相关依赖     (存在jsp页面下载问题,可能是缺少tomcat-embed-jasper的依赖对jsp的支持) <parent> <groupId>org.spri ...

  3. 20-2 树莓派搭建服务器 Tornado Web服务器

    Drive.google.com/drive/folders/1ahbeoEHkjxoo4NV1wReOmpoRWbl448z- 1.Tornado简介 Tornado一款使用 Python 编写的, ...

  4. (知识点4)C++ 中vector

    1.定义vector<vector<int>> M; 2.添加元素这里是vector的嵌套使用,本质是vector元素里的每个元素也是vector类型,所以抓住本质来添加元素就 ...

  5. Numpy | 10 广播(Broadcast)

    广播(Broadcast)是 numpy 对不同形状(shape)的数组进行数值计算的方式, 对数组的算术运算通常在相应的元素上进行. 下面的图片展示了数组 b 如何通过广播来与数组 a 兼容. 4x ...

  6. 请找出"aaaabbcccdddd"字符串中出现最多的字母

    function getCount(str) { for(var code=32;code<128;code++){ var mych=String.fromCharCode(code); va ...

  7. MinHook库的使用 64位下,过滤LoadLibraryExW

    目录 一丶简介 1.minHook库的下载以及安装. 二丶使用MinHook库,过滤LoadLibraryExW 2.1编写X64测试程序. 2.2使用MinHook库 2.3完整HOOK代码 Min ...

  8. shell 文件的包含

    使用.或者source api.sh function intadd() { let data=$+$ echo $data } test.sh #!/bin/bash . api.sh read d ...

  9. 重置GPU显存 Reset GPU memory after CUDA errors

    Sometimes CUDA program crashed during execution, before memory was flushed. As a result, device memo ...

  10. javaweb利用filter拦截未授权请求

    项目上有个小需求,要限制访问者的IP,屏蔽未授权的请求.该场景使用过滤器来做再合适不过了. SecurityFilter.java: public class SecurityFilter imple ...