{"id":42835,"date":"2024-12-01T09:41:22","date_gmt":"2024-12-01T01:41:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/42835\/"},"modified":"2024-12-01T09:41:22","modified_gmt":"2024-12-01T01:41:22","slug":"%e9%98%bb%e6%ad%a2-godog-%e8%a7%a3%e6%9e%90-scenario-outline-%e7%a4%ba%e4%be%8b%e6%95%b0%e6%8d%ae%e8%a1%a8%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/42835\/","title":{"rendered":"\u963b\u6b62 godog \u89e3\u6790 Scenario Outline \u793a\u4f8b\u6570\u636e\u8868\u884c"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u963b\u6b62 godog \u89e3\u6790 Scenario Outline \u793a\u4f8b\u6570\u636e\u8868\u884c<\/span><\/p>\n<h1>\u963b\u6b62 godog \u89e3\u6790 Scenario Outline \u793a\u4f8b\u6570\u636e\u8868\u884c<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-26 14:48:35<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u963b\u6b62 godog \u89e3\u6790 Scenario Outline \u793a\u4f8b\u6570\u636e\u8868\u884c\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u4e0d\u786e\u5b9a\u8fd9\u662f\u5426\u662f\u6709\u610f\u4e3a\u4e4b\uff0c\u4f46\u6211\u5bf9\u8fd9\u79cd\u884c\u4e3a\u611f\u5230\u56f0\u60d1\u3002<\/p>\n<p>\u5f53\u6211\u6709\u4ee5\u4e0b\u573a\u666f\u5927\u7eb2\u65f6\uff1a<\/p>\n<pre>scenario outline: outline1\ngiven url\nand query parameters &lt;query_params&gt;\nwhen method\nthen status is\nexamples:\n| method | endpoint   | query_params | status |\n| get    | \/endpoint1 | ?a=1&amp;b=1     | 200    |\n| get    | \/endpoint1 | ?a=1&amp;b=1&amp;c=3 | 200    |<\/pre>\n<p>\u6211\u770b\u5230\u751f\u6210\u4e86\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\u3002<\/p>\n<pre>func FeatureContext(s *godog.Suite) {\ns.Step(^method GET$, methodGET)\ns.Step(^query parameters \\?a=(\\d+)&amp;b=(\\d+)$, queryParametersAB)\ns.Step(^query parameters \\?a=(\\d+)&amp;b=(\\d+)&amp;c=(\\d+)$, queryParametersABC)\n}<\/pre>\n<p>\u5982\u60a8\u6240\u89c1\uff0c2 \u884c\u201c\u67e5\u8be2\u53c2\u6570\u201d\u4ea7\u751f 2 \u4e2a\u4e0d\u540c\u7684\u51fd\u6570\u3002 godog \u4e3a\u4ec0\u4e48\u8981\u89e3\u6790\u8fd9\u6bb5\u6587\u672c\uff1f\u8fd9\u4e0e\u9ec4\u74dc\u5c0f\u9ec4\u74dc\u89e3\u6790\u6709\u70b9\u4e0d\u540c\u3002<\/p>\n<p>\u8fd9\u6837\u505a\u7684\u4e00\u4e2a\u526f\u4f5c\u7528\u662f\uff0c\u5982\u679c\u6570\u636e\u8868\u4e2d\u6709 100 \u884c\uff0c\u6211\u5c31\u88ab\u8feb\u5b9e\u73b0\u6240\u6709\u8fd9\u4e9b\u3002<\/p>\n<p>\u6709\u4ec0\u4e48\u529e\u6cd5\u53ef\u4ee5\u8ba9 godog \u4e0d\u505a\u8fd9\u4e2a\u89e3\u6790\u5417\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528\u53cc\u5f15\u53f7\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre>scenario outline: outline1\ngiven url\nand query parameters \"&lt;query_params&gt;\"\nwhen method\nthen status is\nexamples:\n| method | endpoint   | query_params | status |\n| get    | \/endpoint1 | ?a=1&amp;b=1     | 200    |\n| get    | \/endpoint1 | ?a=1&amp;b=1&amp;c=3 | 200    |<\/pre>\n<p>\u7136\u540e\u5c06\u751f\u6210\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>s.Step(`^query parameters \"([^\"]*)\"$`, queryParameters)<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u963b\u6b62 godog \u89e3\u6790 Scenario Outline \u793a\u4f8b\u6570\u636e\u8868\u884c\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u963b\u6b62 godog \u89e3\u6790 Scenario Outline \u793a\u4f8b\u6570\u636e\u8868\u884c \u963b\u6b62 godog \u89e3\u6790 Scenario Outline \u793a\u4f8b\u6570\u636e\u8868\u884c \u6765\u6e90\uff1astackoverflow 2024-04-26 14:48:35 0\u6d4f\u89c8 \u6536\u85cf \u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u6211\u4eec\u8981\u52aa\u529b\u5b66\u4e60\u5566\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u963b\u6b62 godog \u89e3\u6790 Scenario Outline \u793a\u4f8b\u6570\u636e\u8868\u884c\u300b\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4e0b\u6587\u4e2d\u7684\u5185\u5bb9\u6211\u4eec\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u5728\u9605\u8bfb\u672c\u6587\u8fc7\u7a0b\u4e2d\u6709\u9047\u5230\u4e0d\u6e05\u695a\u7684\u5730\u65b9\uff0c\u6b22\u8fce\u7559\u8a00\u5440\uff01\u6211\u4eec\u4e00\u8d77\u8ba8\u8bba\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u4e0d\u786e\u5b9a\u8fd9\u662f\u5426\u662f\u6709\u610f\u4e3a\u4e4b\uff0c\u4f46\u6211\u5bf9\u8fd9\u79cd\u884c\u4e3a\u611f\u5230\u56f0\u60d1\u3002 \u5f53\u6211\u6709\u4ee5\u4e0b\u573a\u666f\u5927\u7eb2\u65f6\uff1a scenario outline: outline1 given url and query parameters &lt;query_params&gt; when method then status is examples: | method | endpoint | query_params | status | [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-42835","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=42835"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/42835\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=42835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=42835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=42835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}