您的位置:软件测试 > 开源软件测试 > 开源单元测试工具 > TestNG
TestNG插件与ANT
作者:网络转载 发布时间:[ 2016/1/12 11:57:35 ] 推荐标签:单元测试工具 软件测试

  创建TestMessageUtil 类在 C: > TestNG_WORKSPACE > TestNGWithAnt > src 目录.
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestMessageUtil {
String message = "Manisha";
MessageUtil messageUtil = new MessageUtil(message);
@Test
public void testPrintMessage() {
System.out.println("Inside testPrintMessage()");
Assert.assertEquals(message,messageUtil.printMessage());
}
@Test
public void testSalutationMessage() {
System.out.println("Inside testSalutationMessage()");
message = "Hi!" + "Manisha";
Assert.assertEquals(message,messageUtil.salutationMessage());
}
}
  拷贝 testng-6.8.jar 到 C: > TestNG_WORKSPACE > TestNGWithAnt > lib 文件夹
  创建 ANT build.xml
  首先,我们需要定义TestNG的ant任务如下:
  <taskdef name="testng" classname="org.testng.TestNGAntTask">
  <classpath>
  <pathelement location="lib/testng-6.8.jar"/>
  </classpath>
  </taskdef>
  然后我们使用 <testng> TestNG的测试案例Ant来执行任务。
  C: > TestNG_WORKSPACE > TestNGWithAnt > build.xml 内容如下:
<project name="TestNGTest" default="test" basedir=".">
<!-- Define <testng> task -->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="lib/testng-6.8.jar"/>
</classpath>
</taskdef>
<property name="testdir" location="test" />
<property name="srcdir" location="src" />
<property name="libdir" location="lib" />
<property name="full-compile" value="true" />
<path id="classpath.base"/>
<path id="classpath.test">
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${testdir}" />
<pathelement location="${srcdir}" />
<path refid="classpath.base" />
</path>
<target name="clean" >
<delete verbose="${full-compile}">
<fileset dir="${testdir}" includes="**/*.class" />
</delete>
</target>
<target name="compile" depends="clean">
<javac srcdir="${srcdir}" destdir="${testdir}"
verbose="${full-compile}">
<classpath refid="classpath.test"/>
</javac>
</target>
<target name="test" depends="compile">
<testng outputdir="${testdir}" classpathref="classpath.test">
<xmlfileset dir="${srcdir}" includes="testng.xml"/>
</testng>
</target>
</project>
  执行下列ant命令。
  C:TestNG_WORKSPACETestNGWithAnt>ant
  验证输出
  test:
  [testng] [TestNG] Running:
  [testng] C:TestNG_WORKSPACETestNGWithAntsrc estng.xml
  [testng]
  [testng] Inside testPrintMessage()
  [testng] Manisha
  [testng] Inside testSalutationMessage()
  [testng] Hi!Manisha
  [testng]
  [testng] ===============================================
  [testng] Plug ANT test Suite
  [testng] Total tests run: 2, Failures: 0, Skips: 0
  [testng] ===============================================
  [testng]
  BUILD SUCCESSFUL
  Total time: 1 second

上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd