自动化测试框架selenium+java+TestNG——TestNG注解、执行、测试结果和测试报告

  TestNG是java的一个测试框架,相比较于junit,功能更强大和完善,我是直接学习和使用的TestNG就来谈下TestNG的一些特点吧。

  TestNG的特点

  • 注解

  • TestNG使用Java和面向对象的功能

  • 支持综合类测试(例如,默认情况下,没有必要创建一个新的测试每个测试方法的类的实例)

  • 独立的编译时间测试代码运行时配置/数据信息

  • 灵活的运行时配置

  • 主要介绍“测试组”。当编译测试,只要问TestNG运行所有的“前端”的测试,或“快”,“慢”,“数据库”等

  • 支持依赖测试方法,并行测试,负载测试,局部故障

  • 灵活的插件API

  • 支持多线程测试

 TestNG注解

     

TestNG的执行

    TestNG有两种执行的方法:

    一种是选择右键要执行的方法,点Run As ->TestNG Test;

    另外一种是通过testng.xml文件来执行. 把要执行的case, 放入testng.xml文件中。 右键点击testng.xml,   点Run As。

    但其实第一种执行的方法也是eclipse默认创建了xml文件执行,文件的地址在执行结果中就有。

TestNG简单例子

package com.testngDemo;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class DemoTestng {
    @BeforeClass
    public void setup()
    {
        System.out.println("begin test");
    }
    @Test
    public void test()
    {
        System.out.println("at test");
    }
    @AfterClass
    public void teardown()
    {
        System.out.println("end test");
    }

}

执行代码:

查看结果:

我们可以在结果中看到xml文件的位置, 测试报告位于 "test-output" 目录下。

 

   

原文地址:https://www.cnblogs.com/dreamyu/p/6403643.html