{"id":94,"date":"2019-06-14T11:11:43","date_gmt":"2019-06-14T03:11:43","guid":{"rendered":"http:\/\/www.anthonylee.cn\/myblog\/?p=94"},"modified":"2019-06-14T11:11:43","modified_gmt":"2019-06-14T03:11:43","slug":"testng%e6%b5%8b%e8%af%95%e6%a1%86%e6%9e%b6%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"http:\/\/www.anthonylee.cn\/myblog\/?p=94","title":{"rendered":"TestNG\u6d4b\u8bd5\u6846\u67b6\u4ecb\u7ecd"},"content":{"rendered":"<h2 id=\"A02_1_2\">TestNG\u662f\u4ec0\u4e48?<\/h2>\n<p>TestNG\u6309\u7167\u5176\u6587\u6863\u7684\u5b9a\u4e49\u662f\uff1a<\/p>\n<ul>\n<li>TestNG\u662f\u4e00\u4e2a\u6d4b\u8bd5\u6846\u67b6\uff0c\u5176\u7075\u611f\u6765\u81eaJUnit\u548cNUnit\u7684\uff0c\u4f46\u5f15\u5165\u4e86\u4e00\u4e9b\u65b0\u7684\u529f\u80fd\uff0c\u4f7f\u5176\u529f\u80fd\u66f4\u5f3a\u5927\uff0c\u4f7f\u7528\u66f4\u65b9\u4fbf\u3002<\/li>\n<li>TestNG\u662f\u4e00\u4e2a\u5f00\u6e90\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6;TestNG\u8868\u793a\u4e0b\u4e00\u4ee3\u3002 TestNG\u662f\u7c7b\u4f3c\u4e8eJUnit\uff08\u7279\u522b\u662fJUnit 4\uff09\uff0c\u4f46\u5b83\u4e0d\u662f\u4e00\u4e2aJUnit\u6269\u5c55\u3002\u5b83\u7684\u7075\u611f\u6765\u6e90\u4e8eJUnit\u3002\u5b83\u7684\u76ee\u7684\u662f\u4f18\u4e8eJUnit\u7684\uff0c\u5c24\u5176\u662f\u5f53\u6d4b\u8bd5\u96c6\u6210\u7684\u7c7b\u3002 TestNG\u7684\u521b\u9020\u8005\u662fCedric Beust\uff08\u585e\u5fb7\u91cc\u514b\u2022\u535a\u4f0a\u65af\u7279\uff09<\/li>\n<li>TestNG\u6d88\u9664\u4e86\u5927\u90e8\u5206\u7684\u65e7\u6846\u67b6\u7684\u9650\u5236\uff0c\u4f7f\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u7f16\u5199\u66f4\u52a0\u7075\u6d3b\u548c\u5f3a\u5927\u7684\u6d4b\u8bd5\u3002 \u56e0\u4e3a\u5b83\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u501f\u9274\u4e86Java\u6ce8\u89e3\uff08JDK5.0\u5f15\u5165\u7684\uff09\u6765\u5b9a\u4e49\u7684\u6d4b\u8bd5\uff0c\u5b83\u4e5f\u53ef\u4ee5\u544a\u8bc9\u4f60\u5982\u4f55\u4f7f\u7528\u8fd9\u4e2a\u65b0\u529f\u80fd\u5728\u771f\u5b9e\u7684Java\u8bed\u8a00\u751f\u4ea7\u73af\u5883\u4e2d\u3002<\/li>\n<\/ul>\n<h2 id=\"A02_1_3\">TestNG\u7684\u7279\u70b9<\/h2>\n<ul>\n<li>\u6ce8\u89e3<\/li>\n<li>TestNG\u4f7f\u7528Java\u548c\u9762\u5411\u5bf9\u8c61\u7684\u529f\u80fd<\/li>\n<li>\u652f\u6301\u7efc\u5408\u7c7b\u6d4b\u8bd5\uff08\u4f8b\u5982\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6ca1\u6709\u5fc5\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6d4b\u8bd5\u6bcf\u4e2a\u6d4b\u8bd5\u65b9\u6cd5\u7684\u7c7b\u7684\u5b9e\u4f8b\uff09<\/li>\n<li>\u72ec\u7acb\u7684\u7f16\u8bd1\u65f6\u95f4\u6d4b\u8bd5\u4ee3\u7801\u8fd0\u884c\u65f6\u914d\u7f6e\/\u6570\u636e\u4fe1\u606f<\/li>\n<li>\u7075\u6d3b\u7684\u8fd0\u884c\u65f6\u914d\u7f6e<\/li>\n<li>\u4e3b\u8981\u4ecb\u7ecd\u201c\u6d4b\u8bd5\u7ec4\u201d\u3002\u5f53\u7f16\u8bd1\u6d4b\u8bd5\uff0c\u53ea\u8981\u95eeTestNG\u8fd0\u884c\u6240\u6709\u7684\u201c\u524d\u7aef\u201d\u7684\u6d4b\u8bd5\uff0c\u6216\u201c\u5feb\u201d\uff0c\u201c\u6162\u201d\uff0c\u201c\u6570\u636e\u5e93\u201d\u7b49<\/li>\n<li>\u652f\u6301\u4f9d\u8d56\u6d4b\u8bd5\u65b9\u6cd5\uff0c\u5e76\u884c\u6d4b\u8bd5\uff0c\u8d1f\u8f7d\u6d4b\u8bd5\uff0c\u5c40\u90e8\u6545\u969c<\/li>\n<li>\u7075\u6d3b\u7684\u63d2\u4ef6API<\/li>\n<li>\u652f\u6301\u591a\u7ebf\u7a0b\u6d4b\u8bd5<\/li>\n<\/ul>\n<h2 id=\"A02_1_1\">JUnit\u7f3a\u70b9<\/h2>\n<ul>\n<li>\u6700\u521d\u7684\u8bbe\u8ba1\uff0c\u4f7f\u7528\u4e8e\u5355\u5143\u6d4b\u8bd5\uff0c\u73b0\u5728\u53ea\u7528\u4e8e\u5404\u79cd\u6d4b\u8bd5<\/li>\n<li>\u4e0d\u80fd\u4f9d\u8d56\u6d4b\u8bd5<\/li>\n<li>\u914d\u7f6e\u63a7\u5236\u6b20\u4f73\uff08\u5b89\u88c5\/\u62c6\u5378\uff09<\/li>\n<li>\u4fb5\u5165\u6027\uff08\u5f3a\u5236\u6269\u5c55\u7c7b\uff0c\u5e76\u4ee5\u67d0\u79cd\u65b9\u5f0f\u547d\u540d\u65b9\u6cd5\uff09<\/li>\n<li>\u9759\u6001\u7f16\u7a0b\u6a21\u578b\uff08\u4e0d\u5fc5\u8981\u7684\u91cd\u65b0\u7f16\u8bd1\uff09<\/li>\n<li>\u4e0d\u540c\u7684\u9002\u5408\u7ba1\u7406\u590d\u6742\u9879\u76ee\u4e2d\u7684\u6d4b\u8bd5\u53ef\u4ee5\u662f\u975e\u5e38\u68d8\u624b<\/li>\n<\/ul>\n<h1 id=\"A02_2\">TestNG\u6ce8\u89e3<\/h1>\n<table style=\"font-weight: 400;\" width=\"560\">\n<tbody>\n<tr>\n<td width=\"110\"><strong>\u6ce8\u89e3<\/strong><\/td>\n<td><strong>\u63cf\u8ff0<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>@BeforeSuite<\/strong><\/td>\n<td>\u6ce8\u89e3\u7684\u65b9\u6cd5\u5c06\u53ea\u8fd0\u884c\u4e00\u6b21\uff0c\u8fd0\u884c\u6240\u6709\u6d4b\u8bd5\u524d\u6b64\u5957\u4ef6\u4e2d\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@AfterSuite<\/strong><\/td>\n<td>\u6ce8\u89e3\u7684\u65b9\u6cd5\u5c06\u53ea\u8fd0\u884c\u4e00\u6b21\u6b64\u5957\u4ef6\u4e2d\u7684\u6240\u6709\u6d4b\u8bd5\u90fd\u8fd0\u884c\u4e4b\u540e\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@BeforeClass<\/strong><\/td>\n<td>\u6ce8\u89e3\u7684\u65b9\u6cd5\u5c06\u53ea\u8fd0\u884c\u4e00\u6b21\u5148\u884c\u5148\u8bd5\u5728\u5f53\u524d\u7c7b\u4e2d\u7684\u65b9\u6cd5\u8c03\u7528\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@AfterClass<\/strong><\/td>\n<td>\u6ce8\u89e3\u7684\u65b9\u6cd5\u5c06\u53ea\u8fd0\u884c\u4e00\u6b21\u540e\u5df2\u7ecf\u8fd0\u884c\u5728\u5f53\u524d\u7c7b\u4e2d\u7684\u6240\u6709\u6d4b\u8bd5\u65b9\u6cd5\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@BeforeTest<\/strong><\/td>\n<td>\u6ce8\u89e3\u7684\u65b9\u6cd5\u5c06\u88ab\u8fd0\u884c\u4e4b\u524d\u7684\u4efb\u4f55\u6d4b\u8bd5\u65b9\u6cd5\u5c5e\u4e8e\u5185\u90e8\u7c7b\u7684\u00a0&lt;test&gt;\u6807\u7b7e\u7684\u8fd0\u884c\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@AfterTest<\/strong><\/td>\n<td>\u6ce8\u89e3\u7684\u65b9\u6cd5\u5c06\u88ab\u8fd0\u884c\u540e\uff0c\u6240\u6709\u7684\u6d4b\u8bd5\u65b9\u6cd5\uff0c\u5c5e\u4e8e\u5185\u90e8\u7c7b\u7684&lt;test&gt;\u6807\u7b7e\u7684\u8fd0\u884c\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@BeforeGroups<\/strong><\/td>\n<td>\u6309\u7ec4( @Test(groups= &#8220;findyou&#8221;) )\u8fd0\u884c\u65f6\uff0c\u6b64\u6ce8\u89e3\u5728\u7ec4(findyou\u7ec4)\u6267\u884c\u4e4b\u524d\u8fd0\u884c\uff0c\u53ef\u505a\u7ec4\uff08findyou\u7ec4\uff09\u6267\u884c\u4e4b\u524d\uff0c\u521d\u59cb\u5316\u6570\u636e\u51c6\u5907\u7c7b\u5de5\u4f5c\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@AfterGroups<\/strong><\/td>\n<td>\u6309\u7ec4( @Test(groups= &#8220;findyou&#8221;) )\u8fd0\u884c\u65f6\uff0c\u6b64\u6ce8\u89e3\u5728\u7ec4(findyou\u7ec4)\u6267\u884c\u4e4b\u540e\u8fd0\u884c\uff0c\u53ef\u505a\u7ec4\uff08findyou\uff09\u6267\u884c\u4e4b\u540e\uff0c\u6570\u636e\u8fd8\u539f\u7c7b\u5de5\u4f5c\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@BeforeMethod<\/strong><\/td>\n<td>\u6ce8\u89e3\u7684\u65b9\u6cd5\u5c06\u6bcf\u4e2a\u6d4b\u8bd5\u65b9\u6cd5\u4e4b\u524d\u8fd0\u884c\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@AfterMethod<\/strong><\/td>\n<td>\u88ab\u6ce8\u91ca\u7684\u65b9\u6cd5\u5c06\u88ab\u8fd0\u884c\u540e\uff0c\u6bcf\u4e2a\u6d4b\u8bd5\u65b9\u6cd5\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@DataProvider<\/strong><\/td>\n<td>\u6807\u5fd7\u7740\u4e00\u4e2a\u65b9\u6cd5\uff0c\u63d0\u4f9b\u6570\u636e\u7684\u4e00\u4e2a\u6d4b\u8bd5\u65b9\u6cd5\u3002\u6ce8\u89e3\u7684\u65b9\u6cd5\u5fc5\u987b\u8fd4\u56de\u4e00\u4e2aObject[] []\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5bf9\u8c61[]\u7684\u6d4b\u8bd5\u65b9\u6cd5\u7684\u53c2\u6570\u5217\u8868\u4e2d\u53ef\u4ee5\u5206\u914d\u3002<\/p>\n<p>\u8be5@Test\u00a0\u65b9\u6cd5\uff0c\u5e0c\u671b\u4ece\u8fd9\u4e2aDataProvider\u7684\u63a5\u6536\u6570\u636e\uff0c\u9700\u8981\u4f7f\u7528\u4e00\u4e2adataProvider\u540d\u79f0\u7b49\u4e8e\u8fd9\u4e2a\u6ce8\u89e3\u7684\u540d\u5b57\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@Factory<\/strong><\/td>\n<td>\u4f5c\u4e3a\u4e00\u4e2a\u5de5\u5382\uff0c\u8fd4\u56deTestNG\u7684\u6d4b\u8bd5\u7c7b\u7684\u5bf9\u8c61\u5c06\u88ab\u7528\u4e8e\u6807\u8bb0\u7684\u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u5fc5\u987b\u8fd4\u56deObject[]\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@Listeners<\/strong><\/td>\n<td>\u5b9a\u4e49\u4e00\u4e2a\u6d4b\u8bd5\u7c7b\u7684\u76d1\u542c\u5668\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@Parameters<\/strong><\/td>\n<td>\u4ecb\u7ecd\u5982\u4f55\u5c06\u53c2\u6570\u4f20\u9012\u7ed9@Test\u65b9\u6cd5\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>@Test<\/strong><\/td>\n<td>\u6807\u8bb0\u4e00\u4e2a\u7c7b\u6216\u65b9\u6cd5\u4f5c\u4e3a\u6d4b\u8bd5\u7684\u4e00\u90e8\u5206\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">&lt;\/pre&gt;\r\npackage example1;\r\n\r\nimport org.testng.annotations.*;\r\n\r\npublic class SimpleTest {\r\n\r\n @BeforeClass\r\n public void setUp() {\r\n   \/\/ code that will be invoked when this test is instantiated\r\n }\r\n\r\n @Test(groups = { &quot;fast&quot; })\r\n public void aFastTest() {\r\n   System.out.println(&quot;Fast test&quot;);\r\n }\r\n\r\n @Test(groups = { &quot;slow&quot; })\r\n public void aSlowTest() {\r\n    System.out.println(&quot;Slow test&quot;);\r\n }\r\n\r\n}\r\n\r\n&lt;pre&gt;\r\n<\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c<\/p>\n<p>test:<br \/>\n[testng] Fast test<br \/>\n[testng] ===============================================<br \/>\n[testng] Suite for Command line test<br \/>\n[testng] Total tests run: 1, Failures: 0, Skips: 0<br \/>\n[testng] ===============================================<\/p>\n<p>BUILD SUCCESSFUL<br \/>\nTotal time: 4 seconds<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TestNG\u662f\u4ec0\u4e48? TestNG\u6309\u7167\u5176\u6587\u6863\u7684\u5b9a\u4e49\u662f\uff1a TestNG\u662f\u4e00\u4e2a\u6d4b\u8bd5\u6846\u67b6\uff0c\u5176\u7075\u611f\u6765\u81eaJUn&hellip; <a href=\"http:\/\/www.anthonylee.cn\/myblog\/?p=94\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">TestNG\u6d4b\u8bd5\u6846\u67b6\u4ecb\u7ecd<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/posts\/94"}],"collection":[{"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=94"}],"version-history":[{"count":4,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":98,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions\/98"}],"wp:attachment":[{"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.anthonylee.cn\/myblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}