TestNG 测试工具介绍

可以说TestNG的功能已经盖过了JUnit,如果你用过,一定会说好的。

 

Eclipse plugin:

 

http://beust.com/eclipse

 

安装插件,会添加一个Build library

 

然后就开始我们的操作了

 

添加一个测试类package com.java.test;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeClass;
import org.testng.AssertJUnit;
import java.util.ArrayList;
import java.util.Collection;

public class TestNGTest1 {

    private Collection collection;

    @BeforeClass
    public void oneTimeSetUp() {
        // one-time initialization code
        System.out.println("@BeforeClass - oneTimeSetUp");
    }

    @AfterClass
    public void oneTimeTearDown() {
        // one-time cleanup code
        System.out.println("@AfterClass - oneTimeTearDown");
    }

    @BeforeMethod
    public void setUp() {
        collection = new ArrayList();
        System.out.println("@BeforeMethod - setUp");
    }

    @AfterMethod
    public void tearDown() {
        collection.clear();
        System.out.println("@AfterMethod - tearDown");
    }

    @Test
    public void testEmptyCollection() {
        AssertJUnit.assertEquals(collection.isEmpty(), true);
        System.out.println("@Test - testEmptyCollection");
    }

    @Test
    public void testOneItemCollection() {
        collection.add("itemA");
        AssertJUnit.assertEquals(collection.size(), 1);
        System.out.println("@Test - testOneItemCollection");
    }
}

 

非常像JUnit,这样可以减少很多学习的时间。

 

然后配置 TestNG

 



然后开始 用TestNG插件运行我们的Test class

 

就会出现 测试报告哦

 

还有就是看到 NG状态

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值