可以说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状态