TestNG简介

前言
    前几天在跑一个项目的时候发现它的测试框架是TestNG,以前没接触过,不过看起来跟JUnit差不多,后来通过查阅资料发现有个说法:开发人员用Junit写单元测试,测试人员用TestNG写自动化测试。由此可见TestNG比JUnit要更加强大,今天我们就看看测试人员使用的TestNG究竟是啥,比JUnit强在哪里。

正题
    
1.TestNG介绍

    TestNG(Test Next Generation),是基于JUnit和NUnit并进行了改进的测试框架,它的功能很强大,而且简单易用。
    
    下面是官网的解释:
    TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use, such as:

1)Annotations. 

2)Run your tests in arbitrarily big thread pools with various policies available (all methods in their own  thread, one thread per 

3)test class, etc...).

4)Test that your code is multithread safe.

5)Flexible test configuration.

6)Support for data-driven testing (with @DataProvider).

7)Support for parameters.

8)Powerful execution model (no more TestSuite).

9)Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...).

10)Embeds BeanShell for further flexibility.

11)Default JDK functions for runtime and logging (no dependencies).

12)Dependent methods for application server testing.

TestNG is designed to cover all categories of tests:  unit, functional, end-to-end, integration, etc...

    ps:详情可参考TestNG官网 http://testng.org/doc/index.html
    

2.特点
    上面已经介绍了TestNG的特性,我们可以主要归为几个:
1)更丰富的annotation。

2)使用xml配置文件可以任意组合出需要的各种测试。

3)命令行参数让每一次测试更灵活。


3.Eclipse中安装TestNG
    要想使用TestNG不仅需要相应的jar包还需要对应的插件,安装方式有很多种,对于第一次接触的东西我们可以直接通过Help->Eclipse Marketplace 然后输入tTestNG进行搜索即可。


    安装成功后我们就可以看到了
    

4.简单示例
package com.dan.test;

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

public class TestNG1 {

    @BeforeClass
    public void beforeClass() {
        System.out.println("this is before class");
    }

    @Test
    public void TestNgExample() {
        System.out.println("this is TestNG test case");
    }

    @AfterClass
    public void afterClass() {
        System.out.println("this is after class");
    }
}


    
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值