WEB开发网      婵犻潧鍊婚弲顐︽偟椤栨稓闄勯柦妯侯槸閻庤霉濠婂骸浜剧紒杈ㄥ笚閹峰懘鎮╅崹顐ゆ殸婵炴垶鎸撮崑鎾趁归悩鐑橆棄闁搞劌瀛╃粋宥夘敃閿濆柊锕傛煙鐎涙ê鐏f繝濠冨灴閹啴宕熼鍡╀紘婵炲濮惧Λ鍕叏閳哄懎绀夋繛鎴濈-楠炪垽鎮归崶褍妲婚柛銊ュ缁傚秹鏁撻敓锟� ---闂佹寧娲╅幏锟�
开发学院软件开发Java 使用 TestNG 的新特性管理实际项目中的大量单元测... 阅读

使用 TestNG 的新特性管理实际项目中的大量单元测试

 2010-01-11 00:00:00 来源:WEB开发网 闂侀潧妫撮幏锟�闂佸憡鍨电换鎰版儍椤掑倵鍋撳☉娆嶄沪缂傚稄鎷�婵犫拃鍛粶闁靛洤娲ㄩ埀顒佺⊕閵囩偟绱為敓锟�闂侀潧妫撮幏锟�  闂佺ǹ绻楀▍鏇㈠极閻愬灚瀚梺鍨儏閳ь剙绉归弻銊р偓闈涙啞閻h京鈧敻鍋婇崰鏍х暦閿燂拷
核心提示:TestNG 的示例代码TestNG 提供了从命令行运行测试用例的方法,下面将首先从命令行运行测试用例,使用 TestNG 的新特性管理实际项目中的大量单元测试,假设有如下的测试用例组: 列表 1. TestNG 示例代码packageexample1;importorg.testng.annotations.*;pu

TestNG 的示例代码

TestNG 提供了从命令行运行测试用例的方法。下面将首先从命令行运行测试用例。假设有如下的测试用例组:


列表 1. TestNG 示例代码

package example1; 
 
import org.testng.annotations.*; 
 
public class SimpleTest { 
 
 @Configuration(beforeTestClass = true) 
 public void setUp() { 
  // code that will be invoked when this test is instantiated 
 } 
 
 @Test(groups = { "HelloWorld" }) 
 public void helloWorldTest() { 
  System.out.println("Hello World"); 
  throw new Error(); 
 } 
 
 @Test(threadPoolSize = 10, invocationCount = 5, timeOut = 1000, groups = { "multiple" }) 
 public void multiThreadTest() { 
   System.out.println("MultiThread test"); 
 } 
 
 @Test(groups = { "HelloNature" }) 
 public void helloNatureTest() { 
   System.out.println("Hello Nature"); 
   throw new Error(); 
 } 
} 
 

运行 TestNG 的 Ant 脚本

为了运行这组测试用例,构建了如下的 Ant 运行脚本:


列表 2. 运行测试用例组的 Ant 脚本 build.xml 文件

<project default="test"> 
 
 <path id="cp"> 
  <pathelement location="c:/spark/eclipse/plugins/org.testng.eclipse_4.7.0.0/lib/testng-jdk15.jar"/> 
  <pathelement location="c:\"/> 
 </path> 
 
 <taskdef name="testng" classpathref="cp" 
      classname="org.testng.TestNGAntTask" /> 
 
 <target name="test"> 
  <testng classpathref="cp" groups="HelloWorld, HelloNature"> 
   <classfileset dir="./" includes="example1/*.class"/> 
  </testng> 
 </target> 
 
</project> 

1 2 3 4 5  下一页

Tags:使用 TestNG 特性

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接