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();
        }
    }
}

 

posted @ 2023-08-26 10:58  Mr_sven  阅读(21)  评论(0编辑  收藏  举报