Allure用法
查看官网:https://docs.qameta.io/allure/#_junit_5
源码example: https://github.com/allure-examples/allure-examples/tree/master/allure-junit5/src/test/java/io/qameta/allure/examples/junit5
添加描述信息
package com.allure; import io.qameta.allure.Allure; import io.qameta.allure.Description; import org.junit.jupiter.api.Test; public class AllureDescriptionTest { @Test @Description("静态描述信息") public void annotationDescriptionTest() { } @Test public void dynamicDescriptionTest() { assert 1+1 == 2; Allure.description("动态描述信息"); assert 1+1 == 2; Allure.description("动态描述信息2");//会覆盖上面的描述信息 } }
添加链接信息
package com.allure; import io.qameta.allure.Allure; import io.qameta.allure.Link; import org.junit.jupiter.api.Test; public class AllureLinkTest { @Test @Link(name = "静态链接", url = "https://www.baidu.com") public void staticLinkTest() { assert 1 + 1 == 2; } @Test public void dynamicLinkTest() { assert 1 + 1 == 2; Allure.link("Dynamic link", "https://www.baidu.com"); } }
添加多个链接
@Test @Links({@Link(name = "静态链接1", url = "https://www.baidu.com"), @Link(name = "静态链接2", url = "https://www.baidu.com"), }) public void twoLinks() { assert 1 + 1 == 2; }
重要等级
五种级别 :
BLOCKER("blocker"), 阻塞缺陷(功能未实现,无法下一步)
CRITICAL("critical"), 严重缺陷(功能点缺失)
NORMAL("normal"), 一般缺陷(边界情况,格式错误)
MINOR("minor"), 次要缺陷(界面错误与ui需求不符)
TRIVIAL("trivial"); 轻微缺陷(必须项无提示,或者提示不规范)
package com.allure; import io.qameta.allure.Allure; import io.qameta.allure.Link; import io.qameta.allure.Severity; import io.qameta.allure.SeverityLevel; import org.junit.jupiter.api.Test; public class AllureSeverityTest { @Test @Severity(SeverityLevel.BLOCKER) public void blockerTest() { assert 1 + 1 == 2; } @Test @Severity(SeverityLevel.CRITICAL) public void criticalTest() { assert 1 + 1 == 2; } @Test @Severity(SeverityLevel.NORMAL) public void normalTest() { assert 1 + 1 == 2; } @Test @Severity(SeverityLevel.MINOR) public void minorTest() { assert 1 + 1 == 2; } @Test @Severity(SeverityLevel.TRIVIAL) public void trivialTest() { assert 1 + 1 == 2; } }
添加测试类别
package com.allure; import io.qameta.allure.Feature; import io.qameta.allure.Story; import org.junit.jupiter.api.Test; //用例的模块 @Feature("登录操作") public class AllureFeatureTest { @Test @Story("登录成功") //用例的功能 public void testSomething() throws Exception { System.out.println("success-0000"); } @Test @Story("登录失败") public void testSomething1() throws Exception { System.out.println("fail 11111"); } }
添加测试步骤
package com.allure; import io.qameta.allure.Allure; import io.qameta.allure.Step; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; public class AllureStepTest { @Test public void someTest() throws Exception { //Some code... Allure.step("步骤1",this::step1Logic); Allure.step("步骤2",this::step2Logic); assertThat(1,equalTo(1)); //Some more assertions... } @Step("This is step 1") private void step1Logic() { // Step1 implementation System.out.println("步骤1"); } @Step("This is step 2") private void step2Logic() { // Step2 implementation System.out.println("步骤2"); } }
添加附件
package com.allure; import io.qameta.allure.Allure; import org.junit.jupiter.api.Test; import java.io.FileInputStream; import java.io.FileNotFoundException; public class AllureAttachmentTest { @Test public void addattachTest(){ // 添加文本展示 Allure.addAttachment("My attachment", "My attachment content"); // 添加截图展示 try { Allure.addAttachment("add picture", "image/png",new FileInputStream("D:\\test\\autotest01\\hu1.jpeg"),".jpg"); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律