{"id":808,"date":"2023-03-01T06:45:43","date_gmt":"2023-02-28T22:45:43","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=808"},"modified":"2023-04-05T17:32:35","modified_gmt":"2023-04-05T09:32:35","slug":"testng-dependency-test","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/01\/testng-dependency-test\/","title":{"rendered":"TestNG\u4f9d\u8d56\u6d4b\u8bd5"},"content":{"rendered":"<p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u6309\u987a\u5e8f\u6765\u8c03\u7528\u6d4b\u8bd5\u7528\u4f8b\uff0c\u90a3\u4e48\u6d4b\u8bd5\u7528\u4f8b\u4e4b\u95f4\u5c31\u5b58\u5728\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<p>TestNG\u652f\u6301\u6d4b\u8bd5\u7528\u4f8b\u4e4b\u95f4\u7684\u4f9d\u8d56\uff1a<\/p>\n<p><!-- more --><\/p>\n<ul>\n<li>\u6d4b\u8bd5\u6848\u4f8b\u4f9d\u8d56\uff1a@Test(dependsOnMethods = {&quot;dependedMethods&quot;})<\/li>\n<li>\u6d4b\u8bd5\u7ec4\u4f9d\u8d56\uff1a@Test(dependsOnGroups = {&quot;dependedGroups&quot;})<\/li>\n<\/ul>\n<h2>\u6d4b\u8bd5\u6848\u4f8b\u4f9d\u8d56<\/h2>\n<pre><code class=\"language-java\">package me.yezhou;\n\nimport org.testng.annotations.Test;\n\npublic class DependsOnTest {\n\n    @Test\n    public void onLoad() {\n        System.out.println(&quot;onLoad&quot;);\n    }\n\n    @Test(dependsOnMethods = { &quot;onLoad&quot; })\n    public void onReady() {\n        System.out.println(&quot;onReady&quot;);\n    }\n\n    @Test(dependsOnMethods = { &quot;onReady&quot; })\n    public void onShow() {\n        System.out.println(&quot;onShow&quot;);\n    }\n}<\/code><\/pre>\n<p>\u6d4b\u8bd5\u7ed3\u679c\uff1a<\/p>\n<pre><code>onLoad\nonReady\nonShow\n\n===============================================\nSuite\nTotal tests run: 3, Failures: 0, Skips: 0\n===============================================<\/code><\/pre>\n<h2>\u6d4b\u8bd5\u7ec4\u4f9d\u8d56<\/h2>\n<pre><code class=\"language-java\">package me.yezhou;\n\nimport org.testng.annotations.Test;\n\npublic class DependsOnTest {\n\n    @Test(groups  = { &quot;group1&quot; })\n    public void testCase1() {\n        System.out.println(&quot;testCase1&quot;);\n    }\n\n    @Test(groups = { &quot;group2&quot; })\n    public void testCase2() {\n        System.out.println(&quot;testCase2&quot;);\n    }\n\n    @Test(dependsOnGroups  = { &quot;group1&quot; })\n    public void testCase3() {\n        System.out.println(&quot;testCase3&quot;);\n    }\n\n    @Test(dependsOnGroups  = { &quot;group.*&quot; })\n    public void testCase4() {\n        System.out.println(&quot;testCase4&quot;);\n    }\n}<\/code><\/pre>\n<p>\u6d4b\u8bd5\u7ed3\u679c\uff1a<\/p>\n<pre><code>testCase1\ntestCase2\ntestCase3\ntestCase4\n\n===============================================\nSuite\nTotal tests run: 4, Failures: 0, Skips: 0\n===============================================<\/code><\/pre>\n<blockquote>\n<p>\u6ce8\uff1agroup.* \u662f\u901a\u914d\u7b26<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u6309\u987a\u5e8f\u6765\u8c03\u7528\u6d4b\u8bd5\u7528\u4f8b\uff0c\u90a3\u4e48\u6d4b\u8bd5\u7528\u4f8b\u4e4b\u95f4\u5c31\u5b58\u5728\u4f9d\u8d56\u5173\u7cfb\u3002 TestNG\u652f\u6301\u6d4b\u8bd5\u7528\u4f8b\u4e4b\u95f4\u7684\u4f9d\u8d56\uff1a  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[224],"tags":[],"class_list":["post-808","post","type-post","status-publish","format-standard","hentry","category-testng"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=808"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/808\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}