allure与junit结合生成漂亮的demo
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的更多相关文章
- 【Python】使用Pytest集成Allure生成漂亮的图形测试报告
前言 大概两个月前写过一篇<[测试设计]使用jenkins 插件Allure生成漂亮的自动化测试报告>的博客,但是其实Allure首先是一个可以独立运行的测试报告生成框架,然后才有了Jen ...
- C#自动生成漂亮的水晶效果头像
C#自动生成漂亮的水晶效果头像 与其他的微博系统相同,在“多可内网微博系统”的用户也可上传自己的头像,并支持头像裁剪. 但“多可内网微博系统”的头像可以更漂亮,因为系统实现了水晶效果的头像.C#程序实 ...
- JMeter:生成漂亮的多维度的HTML报告
JMeter:生成漂亮的多维度的HTML报告我们做性能测试的时候会经常使用一些性能测试工具,我个人比较喜欢Jmeter这个工具,但是JMeter这个工具在生成测试报告方面一直有所欠缺.但是JMeter ...
- .NET生成漂亮桌面背景
.NET生成漂亮桌面背景 一天,我朋友指着某某付费软件对我说,这个东西不错,每天生成一张桌面背景,还能学英语(放置名人名言和翻译)!我说,这东西搞不好我也能做,然后朋友说,"如果你搞出来了, ...
- c#每天生成漂亮桌面背景、英文名言、翻译
阅读目录 一.1. 下载bing.com壁纸查询API 二.2. 解析返回的壁纸JSON信息 三.3. 下载完成的壁纸图片 阅读目录 .NET生成漂亮桌面背景 .NET生成漂亮桌面背景 总结 回到目录 ...
- 如何使用Swagger-UI在线生成漂亮的接口文档
一.简单介绍 Swagger是一个实现了OpenAPI(OpenAPI Specification)规范的工具集.OpenAPI是Linux基金会的一个项目,试图通过定义一种用来描述API格式或API ...
- 【测试设计】使用jenkins 插件Allure生成漂亮的自动化测试报告
前言 以前做自动化测试的时候一直用的HTMLTestRunner来生成测试报告,后来也尝试过用Python的PyH模块自己构建测试报告,在后来看到了RobotFramework的测试报告,感觉之前用的 ...
- pytest + allure + jenkins 生成漂亮的测试报告
pytest我在上一篇文章初始pytest中已有介绍,是一个很理想的Python测试框架.Allure是一款非常轻量级并且非常灵活的开源测试报告生成框架. 它支持绝大多数测试框架, 例如TestNG. ...
- 使用Allure+testNG自动生成漂亮强大的测试用例报告
最近领导让我找一个可以每次打包自动生成测试用例的东西,jenkins或者idea都可以, 最后找到了这个allure,也踩了很多坑,废话不多说!,总结一下: 1 使用原生allure 添加依赖: &l ...
随机推荐
- C++学习(7)—— 函数提高
1. 函数默认参数 在C++中,函数的形参列表中的形参是可以有默认值的 语法:返回值类型 函数名 (参数=默认值){} 注意 如果某个位置已经有了默认参数,那么从这个位置往后,从左到右都必须有默认值 ...
- linux lvm管理基础教程
linux lvm管理基础教程 本人是在redhat7.x系统上亲测lvm管理功能,至于文中所受的CentOS 6 没有亲自试过. 本文来自:https://geekpeek.net/lvm-phys ...
- rsa 解密过程
直接扣js代码 $w = {}; if (typeof $w.RSAUtils === 'undefined') var RSAUtils = $w.RSAUtils = {}; var biRadi ...
- 项目Beta冲刺(团队)--6/7
课程名称:软件工程1916|W(福州大学) 作业要求:项目Beta冲刺 团队名称:葫芦娃队 作业目标:进行新一轮的项目冲刺,尽力完成并完善项目 团队博客 队员学号 队员昵称 博客地址 04160242 ...
- 通过PHP自带的$_SERVER判断 自动识别移动设备
因为站点需要,手机端和PC端分离,所以通过PHP自带的$_SERVER判断 自动识别移动设备 代码如下: <?php $agent = $_SERVER['HTTP_USER_AGENT']; ...
- JMeter基础【第六篇】JMeter5.1事务、检查点、集合点、思考时间、其余设置等
JMeter5.1事务.检查点.集合点.思考时间.其余设置等
- call和apply的模拟实现
call 一句话介绍 call: call() 方法在使用一个指定的 this 值和若干个指定的参数值的前提下调用某个函数或方法. 举个例子: var foo = { value: 1 }; func ...
- Edraw Max 9.4 Crack Method
使用010editor修改以下两个文件. BaseCore.dll (修改二进制内容hex) Before C6 45 C8 62 C6 45 C9 64 C6 45 CA 65 C6 45 CB 6 ...
- 关于单片机的RAM
一块RAM 分为了 堆 和 栈 名词而已,知道就可以了, 各种内存溢出问题: 全局数组访问越界 出现的问题:直接重启,或者死机 解决办法 : 额,写好自己的程序吧!!!!!!! 函数的局部变量过 ...
- 部署django到服务器
部署 服务器环境配置 在本地的虚拟环境中,项目根目录下,执行命令收集所有的包 pip freeze > plist.txt 安装并创建虚拟环境,如已创建则跳过此步 sudo apt-get in ...