简介
TestNG是Java中的一个测试框架, 类似于JUnit 和NUnit, 功能都差不多, 只是功能更加强大,使用也更方便
Java中已经有一个JUnit的测试框架了。 TestNG比JUnit功能强大的多。 测试人员一般用TestNG来写自动化测试。 开发人员一般用JUnit写单元测试。
官方网站: http://testng.org/doc/index.html
安装
一、在线安装
打开Eclipse Help ->Install New Software , 然后Add "http://beust.com/eclipse"
二、一个离线安装的方法,及安装文件:
1.下载附件,并解压。(后面有),或者百度网盘链接: http://pan.baidu.com/s/1c0FBo1y 密码: heqs
2.将解压后的文件..\eclipse-testng离线包\features\目录下的文件夹org.testng.eclipse_6.8.6.20130607_0745放到eclipse--》features目录下
3.将解压后的文件..\eclipse-testng离线包\org.testng.eclipse_6.8.6.20130607_0745文件夹放到eclipse--》plugins目录下
4.重启eclipse
5.验证是否安装成功,file-->new-->other-->TestNg 或者 windowns-->show view-->other-->java
简单列子
import static org.testng.AssertJUnit.assertEquals; import org.testng.annotations.Test; public class TestNGSimpleTest { @Test public void testAdd() { String str = "TestNG is working fine"; assertEquals("TestNG is working fine", str); } @Test public void testAdd1() { String str = "TestNG1 is working fine"; assertEquals("TestNG is working fine", str); } }
在代码右键-->run as-->testng
运行结果
[TestNG] Running: C:\Users\User\AppData\Local\Temp\testng-eclipse-791792894\testng-customsuite.xml PASSED: testAdd FAILED: testAdd1 java.lang.AssertionError: expected:<TestNG is working fine> but was:<TestNG1 is working fine> at org.testng.AssertJUnit.assertEquals(AssertJUnit.java:101) at org.testng.AssertJUnit.assertEquals(AssertJUnit.java:108) at TestNGSimpleTest.testAdd1(TestNGSimpleTest.java:13) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:335) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) =============================================== Default test Tests run: 2, Failures: 1, Skips: 0 =============================================== =============================================== Default suite Total tests run: 2, Failures: 1, Skips: 0 =============================================== [TestNG] Time taken by [email protected]: 12 ms [TestNG] Time taken by [email protected]: 3 ms [TestNG] Time taken by [email protected]: 5 ms [TestNG] Time taken by [email protected]: 28 ms [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 4 ms [TestNG] Time taken by [email protected]: 26 ms
时间: 2024-10-23 10:26:26