要使用Eclipse设置TestNG,请按照下面给出的步骤 :
步骤1:下载TestNG存档
下载最新版本的来自 http://www.testng.org的TestNG jar文件
OS | 存档名称 |
---|---|
Windows | testng-6.8.jar |
Linux | testng-6.8.jar |
Mac | testng-6.8.jar |
我们假设您已将上述JAR文件复制到C:\> TestNG文件夹中.
第2步:设置Eclipse环境
打开eclipse → 右键单击该项目并转到property → Build Path → 配置构建路径并使用添加外部Jar 按钮在库中添加testng-6.8.jar.
我们假设您的Eclipse内置了TestNG插件;如果没有,请使用更新站点获取最新版本.
在Eclipse IDE中,选择帮助/软件更新/查找并安装.
搜索要安装的新功能.
新的远程站点.
对于Eclipse 3.4及更高版本,输入http://beust.com/eclipse .
对于Eclipse 3.3及更低版本,输入 http://beust.com/eclipse1 .
确保选中URL旁边的复选框,然后单击下一步.
Eclipse将引导您完成整个过程.
现在,你的Eclipse准备好了TestNG测试用例的开发.
步骤3:验证Eclipse中的TestNG安装
在Eclipse中的任何位置创建一个项目TestNGProject.
创建一个MessageUtil类以在项目中进行测试.
/** This class prints the given message on console.*/public class MessageUtil { private String message; //Constructor //@param message to be printed public MessageUtil(String message) { this.message = message; } // prints the message public String printMessage() { System.out.println(message); return message; } }
在中创建一个测试类TestNGExample项目.
import org.testng.Assert;import org.testng.annotations.Test;public class TestNGExample { String message = "Hello World"; MessageUtil messageUtil = new MessageUtil(message); @Test public void testPrintMessage() { Assert.assertEquals(message,messageUtil.printMessage()); }}
项目结构应如下 :
最后,通过右键单击程序并作为TestNG运行来验证程序的输出.
验证结果.