测试: TestNg + Allure Java项目单元测试生成测试报告

TestNg + Allure 生成测试报告

完成后结果如图
在这里插入图片描述
在这里插入图片描述

介绍

  • TestNg 是基于Junit 的测试框架
  • Allure 监听测试信息,生成报告

使用

  • 因项目需要,我也是第一次编写测试用例,并生成报告,在网上找的这套方案.

TestNg

  • 项目导入依赖
    <!--测试相关-->
    
        <dependency>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-testng</artifactId>
            <version>2.0-BETA18</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.10</version>
        </dependency>
    
  • maven 编译插件
    <!--testNG + allure 生成测试报告-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <skipTests>true</skipTests>
                    <argLine>
                        -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.2/aspectjweaver-1.9.2.jar"
                    </argLine>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>1.9.2</version>
                    </dependency>
                </dependencies>
            </plugin>
    
  • 编写测试用例,注意@Test 注解使用testNg 相关包
    @WebAppConfiguration()
    @RunWith(SpringRunner.class)
    @SpringBootTest
    @Slf4j
    public class TestNg extends AbstractTestNGSpringContextTests {
        @Test(description = "testNg 通过")
        public void testSuccess() {
            Assert.assertEquals(1, 1);
            System.out.println("测试通过");
        }
    }
    
    在这里插入图片描述

Allure 报告工具使用

  • 安装 : 需要node 环境,安装命令,allure 需要jdk 1.8及以上

    npm install -g allure-commandline --save-dev
    
  • 配置文件 allure.properties ,可以定义报告文件输出路径

    # 定义输出在项目 target 目录
    allure.results.directory=target/allure-results
    
  • allure 命令.输入 allure -h 查看

    Cai:bxadex-deal miya$ allure -help
    Could not parse arguments: Expected a command, got -help
    Usage: allure [options] [command] [command options]
    Options:
    --help
      Print commandline help.
    -q, --quiet
      Switch on the quiet mode.
      Default: false
    -v, --verbose
      Switch on the verbose mode.
      Default: false
    --version
      Print commandline version.
      Default: false
    Commands:
    generate      Generate the report
      Usage: generate [options] The directories with allure results
        Options:
          -c, --clean
            Clean Allure report directory before generating a new one.
            Default: false
          --config
            Allure commandline config path. If specified overrides values from 
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses 
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.
          -o, --report-dir, --output
            The directory to generate Allure report into.
            Default: allure-report
    serve      Serve the report
      Usage: serve [options] The directories with allure results
        Options:
          --config
            Allure commandline config path. If specified overrides values from 
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses 
            ALLURE_HOME directory.
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0
          --profile
            Allure commandline configuration profile.
    
    open      Open generated report
      Usage: open [options] The report directory
        Options:
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0
    
    plugin      Generate the report
      Usage: plugin [options]
        Options:
          --config
            Allure commandline config path. If specified overrides values from 
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses 
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.
    
    
  • 找到serve 服务相关操作, 可以使用 -p 指定端口启动,不然每次启动都是随机端口

    allure serve -p target/allure-results/
    
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值