[自动化测试 - 环境搭建] ANT + Selenium2 + TestNG 整合详细介绍

1.    环境配置

Apache  Ant:        http://ant.apache.org/
TestNG:                http://testng.org/doc/index.html
Selenium:                  http://docs.seleniumhq.org/


2.    新建项目
Eclipse :   File  ->  New  ->  Java Project





3.    新建项目下所需要的文件夹,并将需要用到文件copy过去,并在Eclipse中导入相关的包
Eclipse:  右键项目,选择 New  ->   Folder


[1] 根目录下新建  - [ lib ]
        解压缩testng-xslt-1.1.2.zip 并将  testng-xslt/lib 下的saxon-8.7.jar和SaxonLiaison.jar拷贝到项目的lib目录下
       将下载的testng-6.9.10.jar 和 selenium-server-standalone-2.52.0.jar包拷贝到项目的lib目录下

[2] 根目录下新建  - [  test-output ]
        解压缩testng-xslt-1.1.2.zip 并将  testng-xslt/src/main/resources下的testng-results.xsl拷贝到项目的test-output目录下




[3] 将包导入到项目中
Eclipse:  右键项目,选择 Build Path    ->   Configure Build Path...


点击  Add JARs... ,选择项目lib目录下的jar包并确定



4.    新建测试类
Eclipse:  右键项目,选择  New   ->   Class


填入相关参数后点击完成



5.    编写测试类
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="kwd" style="color: rgb(30, 52, 123);">package</span><span class="pln" style="color: rgb(72, 72, 76);"> demo</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">test</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="kwd" style="color: rgb(30, 52, 123);">import</span><span class="pln" style="color: rgb(72, 72, 76);"> org</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">openqa</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">selenium</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">WebDriver</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="kwd" style="color: rgb(30, 52, 123);">import</span><span class="pln" style="color: rgb(72, 72, 76);"> org</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">openqa</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">selenium</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">firefox</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">FirefoxDriver</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="kwd" style="color: rgb(30, 52, 123);">import</span><span class="pln" style="color: rgb(72, 72, 76);"> org</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">testng</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">annotations</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">AfterClass</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="kwd" style="color: rgb(30, 52, 123);">import</span><span class="pln" style="color: rgb(72, 72, 76);"> org</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">testng</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">annotations</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">BeforeClass</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="kwd" style="color: rgb(30, 52, 123);">import</span><span class="pln" style="color: rgb(72, 72, 76);"> org</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">testng</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">annotations</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Parameters</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="kwd" style="color: rgb(30, 52, 123);">import</span><span class="pln" style="color: rgb(72, 72, 76);"> org</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">testng</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">annotations</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Test</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"> </code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="kwd" style="color: rgb(30, 52, 123);">import</span><span class="pln" style="color: rgb(72, 72, 76);"> com</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">beust</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">jcommander</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="typ" style="color: teal;">Parameter</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"> </code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">class</span><span class="pln" style="color: rgb(72, 72, 76);"> testPara </span><span class="pun" style="color: rgb(147, 161, 161);">{</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">
</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="kwd" style="color: rgb(30, 52, 123);">private</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">WebDriver</span><span class="pln" style="color: rgb(72, 72, 76);"> dirver</span><span class="pun" style="color: rgb(147, 161, 161);">;</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;">
</div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="lit" style="color: rgb(25, 95, 145);">@BeforeClass</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">BeforeClass</span><span class="pun" style="color: rgb(147, 161, 161);">(){</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">		dirver </span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">new</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">FirefoxDriver</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="lit" style="color: rgb(25, 95, 145);">@Parameters</span><span class="pun" style="color: rgb(147, 161, 161);">({</span><span class="str" style="color: rgb(221, 17, 68);">"url"</span><span class="pun" style="color: rgb(147, 161, 161);">})</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="lit" style="color: rgb(25, 95, 145);">@Test</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">GoToLink</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="typ" style="color: teal;">String</span><span class="pln" style="color: rgb(72, 72, 76);"> url</span><span class="pun" style="color: rgb(147, 161, 161);">){</span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">		dirver</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">get</span><span class="pun" style="color: rgb(147, 161, 161);">(</span><span class="pln" style="color: rgb(72, 72, 76);">url</span><span class="pun" style="color: rgb(147, 161, 161);">);</span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="lit" style="color: rgb(25, 95, 145);">@AfterClass</span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="kwd" style="color: rgb(30, 52, 123);">public</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">void</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">AfterClass</span><span class="pun" style="color: rgb(147, 161, 161);">(){</span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">		dirver</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">close</span><span class="pun" style="color: rgb(147, 161, 161);">();</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);">}</span></code></div></div>

6.    在根目录下新建testng.xml 并进行编写
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><?</span><span class="pln" style="color: rgb(72, 72, 76);">xml version</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"1.0"</span><span class="pln" style="color: rgb(72, 72, 76);"> encoding</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"UTF-8"</span><span class="pun" style="color: rgb(147, 161, 161);">?></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><!</span><span class="pln" style="color: rgb(72, 72, 76);">DOCTYPE suite SYSTEM </span><span class="str" style="color: rgb(221, 17, 68);">"http://testng.org/testng-1.0.dtd"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">suite name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"DemoTest1"</span><span class="pln" style="color: rgb(72, 72, 76);"> verbose</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">'1'</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">test name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"testPara"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">parameter name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"url"</span><span class="pln" style="color: rgb(72, 72, 76);"> value</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"http://www.baidu.com"</span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">classes</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="kwd" style="color: rgb(30, 52, 123);">class</span><span class="pln" style="color: rgb(72, 72, 76);"> name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"demo.test.testPara"</span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">classes</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">test</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">suite</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>
截止此处,已经可以直接运行testng.xml
Eclipse:  右键testng.xml,选择 Run As    ->   TestNG Suite


7.    在根目录下新建build.xml 并进行编写
将项目整合到ANT中,使得项目不受平台和IDE的限制而更快的被部署, 一般Eclipse都自带ANT,无需另外安装。
<div class="linenums" style="margin: 0px; color: rgb(30, 52, 123); padding-left: 30px !important;"><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><?</span><span class="pln" style="color: rgb(72, 72, 76);">xml version</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"1.0"</span><span class="pln" style="color: rgb(72, 72, 76);"> encoding</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"UTF-8"</span><span class="pun" style="color: rgb(147, 161, 161);">?></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">project name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"TestNG"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="kwd" style="color: rgb(30, 52, 123);">default</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"testoutput"</span><span class="pln" style="color: rgb(72, 72, 76);"> basedir</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"."</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"> </code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">property name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"srcdir"</span><span class="pln" style="color: rgb(72, 72, 76);"> location</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${basedir}/src"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">property name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"libdir"</span><span class="pln" style="color: rgb(72, 72, 76);"> location</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${basedir}/lib"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">property name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"testng.output.dir"</span><span class="pln" style="color: rgb(72, 72, 76);"> location</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${basedir}/test-output"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">property name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"testng.file"</span><span class="pln" style="color: rgb(72, 72, 76);"> value</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"testng.xml"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"> </code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">path id</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"classpath"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">fileset dir</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${libdir}"</span><span class="pln" style="color: rgb(72, 72, 76);"> includes</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"*jar"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">fileset dir</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${libdir}"</span><span class="pln" style="color: rgb(72, 72, 76);"> includes</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"*zip"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">pathelement location</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${basedir}/bin"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">path</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"> </code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Define</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">testng</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="pln" style="color: rgb(72, 72, 76);"> task </span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">taskdef name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"testng"</span><span class="pln" style="color: rgb(72, 72, 76);"> classname</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"org.testng.TestNGAntTask"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">classpath</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">      		</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">pathelement location</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"./lib/testng-6.9.10.jar"</span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    	</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">classpath</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">taskdef</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"> </code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Before</span><span class="pln" style="color: rgb(72, 72, 76);"> compile</span><span class="pun" style="color: rgb(147, 161, 161);">,</span><span class="kwd" style="color: rgb(30, 52, 123);">delete</span><span class="pln" style="color: rgb(72, 72, 76);"> the previous folder </span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">target name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"clean"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="kwd" style="color: rgb(30, 52, 123);">delete</span><span class="pln" style="color: rgb(72, 72, 76);"> dir</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${basedir}/bin"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">target</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">   </span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">   </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Compile</span><span class="pln" style="color: rgb(72, 72, 76);"> file in </span><span class="str" style="color: rgb(221, 17, 68);">'srcdir'</span><span class="pln" style="color: rgb(72, 72, 76);"> to </span><span class="str" style="color: rgb(221, 17, 68);">'destdir'</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);"> 	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">target name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"compile"</span><span class="pln" style="color: rgb(72, 72, 76);"> depends</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"clean"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">mkdir dir</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${basedir}/bin"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">javac srcdir</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${srcdir}"</span><span class="pln" style="color: rgb(72, 72, 76);"> encoding</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"UTF-8"</span><span class="pln" style="color: rgb(72, 72, 76);"> destdir</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${basedir}/bin"</span><span class="pln" style="color: rgb(72, 72, 76);"> classpathref</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"classpath"</span><span class="pln" style="color: rgb(72, 72, 76);"> includeantruntime</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"off"</span><span class="pln" style="color: rgb(72, 72, 76);"> debug</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"on"</span><span class="pln" style="color: rgb(72, 72, 76);"> debuglevel</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"lines,vars,source"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">target</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);"> use testng</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">xml to run the test </span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">target name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"runtest"</span><span class="pln" style="color: rgb(72, 72, 76);"> depends</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"compile"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	   </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">testng outputdir</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${testng.output.dir}"</span><span class="pln" style="color: rgb(72, 72, 76);"> classpathref</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"classpath"</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">xmlfileset dir</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${basedir}"</span><span class="pln" style="color: rgb(72, 72, 76);"> includes</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"${testng.file}"</span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	   	</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">testng</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">target</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">	</span></code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"><!--</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="typ" style="color: teal;">Use</span><span class="pln" style="color: rgb(72, 72, 76);"> xslt to modify the report  </span><span class="pun" style="color: rgb(147, 161, 161);">--></span></code></div><div class="L0" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">target name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"testoutput"</span><span class="pln" style="color: rgb(72, 72, 76);"> depends</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"runtest"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L1" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">xslt in</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"${testng.output.dir}/testng-results.xml"</span><span class="pln" style="color: rgb(72, 72, 76);"> style</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"${testng.output.dir}/testng-results.xsl"</span></code></div><div class="L2" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">          out</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"${testng.output.dir}/index1.html "</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L3" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">param name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"testNgXslt.outputDir"</span><span class="pln" style="color: rgb(72, 72, 76);"> expression</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"${basedir}/test-output/"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L4" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">param name</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"testNgXslt.showRuntimeTotals"</span><span class="pln" style="color: rgb(72, 72, 76);"> expression</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="str" style="color: rgb(221, 17, 68);">"true"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L5" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">            </span><span class="pun" style="color: rgb(147, 161, 161);"><</span><span class="pln" style="color: rgb(72, 72, 76);">classpath refid</span><span class="pun" style="color: rgb(147, 161, 161);">=</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="str" style="color: rgb(221, 17, 68);">"classpath"</span><span class="pln" style="color: rgb(72, 72, 76);"> </span><span class="pun" style="color: rgb(147, 161, 161);">/></span></code></div><div class="L6" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">        </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">xslt</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div><div class="L7" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pln" style="color: rgb(72, 72, 76);">    </span><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">target</span><span class="pun" style="color: rgb(147, 161, 161);">></span><span class="pln" style="color: rgb(72, 72, 76);"> </span></code></div><div class="L8" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"> </code></div><div class="L9" style="margin: 0px; color: rgb(190, 190, 197); line-height: 18px; padding-left: 12px !important; list-style-type: decimal !important;"><code class="language-java" style="margin: 8px 0px; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; word-wrap: break-word;"><span class="pun" style="color: rgb(147, 161, 161);"></</span><span class="pln" style="color: rgb(72, 72, 76);">project</span><span class="pun" style="color: rgb(147, 161, 161);">></span></code></div></div>

8.    利用ANT执行build.xml
Eclipse:  右键testng.xml,选择 Run As    ->   Ant Build



9.    执行结果


10.    TestNG报告
美化前:

美化后:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值