Junit5集成Allure报告

官方文档: https://docs.qameta.io/allure/
 

★ 查看文档

进入官网,点击左侧 Java → Junit5Junit5集成Allure报告_第1张图片

将pom.xml文件中内容Copy到项目中
其中显示LAST_VERSION的可以通过Maven仓库中搜索对应的版本填充https://mvnrepository.com/
 


    4.0.0
    Testing
    RequestDemo
    1.0-SNAPSHOT
    
        1.8.10
    
    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.8
                    1.8
                    UTF-8
                
            
            
            
            
                maven-surefire-plugin
                2.22.2
                
                    false
                    
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    
                    
                        
                            junit.jupiter.extensions.autodetection.enabled
                            true
                        
                    
                
                
                    
                        org.junit.platform
                        junit-platform-surefire-provider
                        1.2.0
                    
                    
                    org.aspectj
                    aspectjweaver
                    ${aspectj.version}
                    
                    
                        org.junit.jupiter
                        junit-jupiter-engine
                        5.5.2
                    
                
            
            
                io.qameta.allure
                allure-maven
                2.10.0
                
                    2.13.2
                
            
        
    
    
        
            io.rest-assured
            rest-assured
            4.3.0
            test
        
        
            org.junit.jupiter
            junit-jupiter-engine
            5.5.2
            test
        
        
            org.junit.platform
            junit-platform-runner
            1.5.2
            test
        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.11.0
        
        
        
            io.qameta.allure
            allure-junit5
            2.13.2
            test
        
    

 

 

★ 常用注释

@DisplayName("创建部门")
@Description("说明XXXXX")
@Link("www.baidu.com")//添加超链接
@Issue("001")//添加用例编号
@Severity(SeverityLevel.BLOCKER)//设置用例等级
    用例等级:
     Junit5集成Allure报告_第2张图片
 
添加图片:
 
Allure.addAttachment("demo picture",
"image/png",
new FileInputStream("C:\\Users\\Administrator\\Pictures\\123.png"),"png");
添加步骤:
@Test
public void StepTest(){
    step1();
    step2();
}

@Step("这是创建部门第一步")
public void step1(){
    System.out.println("步骤1");
}

@Step("这是创建部门第二步")
public void step2(){
    System.out.println("步骤2");
}

 

★ 查看报告

在命令行中输入:mvn test
allure generate allure-results/
    此命令需要本地已安装 Allure,如未安装可参考我的另一篇博文: https://blog.csdn.net/Guo_Test/article/details/107094612
输入后会在项目根目录下生成一个 allure-report 目录,点击index.html可打开静态测试报告
Junit5集成Allure报告_第3张图片
 
 
问题:如果使用Chrome打开报告后没有显示内容,通过开发者模式可以看到下列报错信息:
Junit5集成Allure报告_第4张图片
关闭Chrome浏览器,右键Chrome浏览器点击属性,在目标输入栏中加入: --allow-file-access-from-files
Junit5集成Allure报告_第5张图片
重启浏览器后再次打开,将index.html拖入浏览器即可正常显示

你可能感兴趣的:(Junit5集成Allure报告)