{"id":16713,"date":"2024-04-11T15:31:04","date_gmt":"2024-04-11T07:31:04","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=16713"},"modified":"2024-04-15T16:17:48","modified_gmt":"2024-04-15T08:17:48","slug":"go-test","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2024\/04\/11\/go-test\/","title":{"rendered":"go\u8bed\u8a00\u4e4b\u81ea\u52a8\u5316\u6d4b\u8bd5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4e3a\u4ec0\u4e48\u9700\u8981\u81ea\u52a8\u5316\u6d4b\u8bd5\uff1f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>\u786e\u4fdd\u4ee3\u7801\u8d28\u91cf<\/strong><\/mark>\uff1a\u81ea\u52a8\u5316\u6d4b\u8bd5\u53ef\u4ee5\u786e\u4fdd\u4ee3\u7801\u5728\u4fee\u6539\u540e\u4ecd\u7136\u6309\u7167\u9884\u671f\u5de5\u4f5c\u3002\u6bcf\u5f53\u4f60\u66f4\u6539\u4ee3\u7801\u65f6\uff0c\u81ea\u52a8\u5316\u6d4b\u8bd5\u53ef\u4ee5\u5feb\u901f\u5730\u68c0\u67e5\u662f\u5426\u6709\u4efb\u4f55\u56de\u5f52\u9519\u8bef\uff0c\u4ece\u800c\u5e2e\u52a9\u4f60\u4fdd\u6301\u4ee3\u7801\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/li>\n\n\n\n<li><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>\u63d0\u9ad8\u5f00\u53d1\u6548\u7387<\/strong>\uff1a<\/mark>\u901a\u8fc7\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0c\u4f60\u53ef\u4ee5\u5feb\u901f\u5730\u8fd0\u884c\u5927\u91cf\u7684\u6d4b\u8bd5\u7528\u4f8b\uff0c\u8fd9\u6bd4\u624b\u52a8\u6d4b\u8bd5\u8981\u9ad8\u6548\u5f97\u591a\u3002\u8fd9\u6837\u53ef\u4ee5\u8282\u7701\u65f6\u95f4\uff0c\u8ba9\u4f60\u4e13\u6ce8\u4e8e\u7f16\u5199\u65b0\u529f\u80fd\u548c\u6539\u8fdb\u4ee3\u7801\uff0c\u800c\u4e0d\u662f\u5728\u8c03\u8bd5\u4e0a\u82b1\u8d39\u8fc7\u591a\u65f6\u95f4\u3002<\/li>\n\n\n\n<li><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><strong>\u6587\u6863\u4f5c\u7528<\/strong>\uff1a<\/mark>\u6d4b\u8bd5\u7528\u4f8b\u672c\u8eab\u53ef\u4ee5\u4f5c\u4e3a\u4ee3\u7801\u7684\u4e00\u79cd\u6587\u6863\u3002\u5b83\u4eec\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u7279\u5b9a\u7684\u51fd\u6570\u6216\u6a21\u5757\uff0c\u4ee5\u53ca\u9884\u671f\u7684\u884c\u4e3a\u662f\u4ec0\u4e48\u3002\u8fd9\u5bf9\u4e8e\u65b0\u52a0\u5165\u9879\u76ee\u7684\u5f00\u53d1\u8005\u6765\u8bf4\u5c24\u5176\u6709\u7528\u3002<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u4fc3\u8fdb\u6a21\u5757\u5316\u548c\u53ef\u7ef4\u62a4\u6027<\/mark><\/strong>\uff1a\u826f\u597d\u7684\u6d4b\u8bd5\u7528\u4f8b\u9f13\u52b1\u5f00\u53d1\u8005\u7f16\u5199\u6a21\u5757\u5316\u548c\u6613\u4e8e\u6d4b\u8bd5\u7684\u4ee3\u7801\u3002\u8fd9\u6837\u7684\u4ee3\u7801\u7ed3\u6784\u6e05\u6670\uff0c\u66f4\u6613\u4e8e\u7ef4\u62a4\u548c\u6269\u5c55\u3002<\/li>\n\n\n\n<li><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u51cf\u5c11\u98ce\u9669<\/mark><\/strong>\uff1a\u5728\u4ee3\u7801\u5408\u5e76\u5230\u4e3b\u5206\u652f\u4e4b\u524d\u8fd0\u884c\u81ea\u52a8\u5316\u6d4b\u8bd5\u53ef\u4ee5\u51cf\u5c11\u5f15\u5165\u9519\u8bef\u7684\u98ce\u9669\u3002\u8fd9\u6709\u52a9\u4e8e\u4fdd\u62a4\u4ee3\u7801\u5e93\u7684\u6574\u4f53\u5065\u5eb7\uff0c\u5e76\u786e\u4fdd\u53ea\u6709\u7ecf\u8fc7\u9a8c\u8bc1\u7684\u4ee3\u7801\u88ab\u5408\u5e76<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">golang\u63d0\u4f9b\u4e86\u4e00\u4e2atesting\u5305\u7528\u4e8e\u4e3a\u4ee3\u7801\u7f16\u5199\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0c\u8fd8\u6709go test \u547d\u4ee4\uff0c\u7528\u4e8e\u8fd0\u884c\u8fd9\u4e9b\u6d4b\u8bd5\uff0c\u5305\u7684\u7528\u6cd5\u53ef\u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\u67e5\u770b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go doc testing<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5b50\uff1a\u5b9a\u4e49yi.go\u6587\u4ef6\uff0c\u5305\u542b\u4e00\u4e2a\u51fd\u6570abcd\uff0c\u63a5\u6536\u5b57\u7b26\u4e32\u5207\u7247\u5e76\u5c06\u5207\u7247\u9664\u4e86\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5916\u90fd\u4f7f\u7528\u9017\u53f7\u8fde\u63a5\uff0c\u7136\u540e\u901a\u8fc7and \u548c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u8fde\u63a5\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"273\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-3.jpg\" alt=\"\" class=\"wp-image-16719\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-3.jpg 692w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-3-300x118.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-3-600x237.jpg 600w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9a\u4e49\u6d4b\u8bd5\u6587\u4ef6yi_test.go\uff0c\u7f16\u5199\u6d4b\u8bd5\u51fd\u6570\uff0c\u9884\u671f\u7684\u8f93\u51fa\u7ed3\u679c\u4e3aexpected\u7684\u503c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"325\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-3.jpg\" alt=\"\" class=\"wp-image-16720\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-3.jpg 694w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-3-300x140.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-3-600x281.jpg 600w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u4e2d\u7684\u6d4b\u8bd5\u6587\u4ef6\u548c\u6b63\u5f0f\u6587\u4ef6\u90fd\u5728\u540c\u4e00\u5305main\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u653e\u5728\u540c\u4e00\u4e2a\u5305\u4e2d\uff0c\u4f46\u662f\u8c03\u7528\u51fd\u6570abcd()\u7684\u65f6\u5019\u5c31\u9700\u8981\u4f7f\u7528\u5305\u540d\u6765\u8c03\u7528\u4e86\uff0c\u6d4b\u8bd5yi_test.go\u4e2d\u5e94\u8be5\u9075\u5faa\u7684\u89c4\u5219\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6d4b\u8bd5\u6587\u4ef6\u7684\u9876\u90e8\u9700\u8981\u5bfc\u5165testing\u5305<\/li>\n\n\n\n<li>\u6d4b\u8bd5\u51fd\u6570\u5e94\u8be5\u4ee5Test\u5f00\u5934\uff0c\u540e\u9762\u7684\u90e8\u5206\u53ef\u81ea\u5b9a\u4e49\u5373\u53ef<\/li>\n\n\n\n<li>\u6d4b\u8bd5\u51fd\u6570\u63a5\u6536\u5355\u4e2a\u53c2\u6570\uff0c\u4e00\u4e2a\u6307\u5411testing.T\u7684\u6307\u9488\uff0cT \u662f\u4e00\u4e2a\u7ed3\u6784\u4f53<\/li>\n\n\n\n<li>\u53ef\u901a\u8fc7\u8c03\u7528 T \u7ed3\u6784\u4f53\u4e2d\u7684Error\u65b9\u6cd5\u6765\u8f93\u51fa\u6d4b\u8bd5\u5931\u8d25\u4fe1\u606f<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7go test\u547d\u4ee4\u6765\u8fd0\u884c\u6d4b\u8bd5\uff0cgo test\u547d\u4ee4\u5c06\u5728\u5305\u76ee\u5f55\u4e2d\u627e\u5230\u6240\u6709\u540d\u5b57\u4ee5_test.go\u7ed3\u5c3e\u7684\u6587\u4ef6\uff0c\u5e76\u8fd0\u884c\u6587\u4ef6\u4e2d\u4ee5Test\u5f00\u5934\u7684\u6bcf\u4e2a\u51fd\u6570<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">yi_test.go\u4e2d\u9884\u671fyi.go\u4e2d\u7684\u7ed3\u679c\uff0c\u7136\u540e\u6d4b\u8bd5\u4e16\u754c\u7ed3\u679c\u662f\u5426\u4e0e\u9884\u671f\u5339\u914d\uff0c\u4e0b\u9762\u662fgo test\u6307\u5b9a\u6587\u4ef6\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"77\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-2.jpg\" alt=\"\" class=\"wp-image-16724\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-2.jpg 692w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-2-300x33.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-2-600x67.jpg 600w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed3\u679c\u8fd4\u56deok\uff0c\u8bf4\u660e\u9884\u671f\u7ed3\u679c\u4e0e\u5b9e\u9645\u7ed3\u679c\u5339\u914d\uff0c\u6d4b\u8bd5\u6210\u529f<\/p>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\uff1a\u5982\u679c\u76f4\u63a5\u6267\u884cgo test\u4e5f\u53ef\u4ee5\uff0c\u4e0d\u8fc7\u6b64\u65f6\u8fd0\u884c\u7684\u662f\u5168\u90e8\u7684_test.go\u6587\u4ef6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539yi.go\u4e2d\u7684\u8fde\u63a5\u65b9\u5f0f\uff0c\u5728and\u524d\u9762\u6dfb\u52a0\u4e00\u4e2a\u9017\u53f7\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"270\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-3.jpg\" alt=\"\" class=\"wp-image-16726\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-3.jpg 695w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-3-300x117.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-3-600x233.jpg 600w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u770b\u7ed3\u679c\uff0c\u5df2\u7ecf\u62a5\u9519\uff0c\u8bf4\u660e\u4e0e\u9884\u671f\u7ed3\u679c\u4e0d\u5339\u914d\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"691\" height=\"158\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/5-2.jpg\" alt=\"\" class=\"wp-image-16727\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/5-2.jpg 691w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/5-2-300x69.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/5-2-600x137.jpg 600w\" sizes=\"auto, (max-width: 691px) 100vw, 691px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86Error\u65b9\u6cd5\uff0c\u8fd8\u6709\u4e00\u4e2aErrorf\u65b9\u6cd5\uff0cErrorf\u63a5\u6536\u4e00\u4e2a\u5e26\u683c\u5f0f\u5316\u52a8\u8bcd\u7684\u5b57\u7b26\u4e32\uff0c\u7c7b\u4f3cfmt.Sprintf\u548cfmt.Printf\uff0c\u56e0\u6b64\u53ef\u4ee5\u5728\u6253\u5370\u7ed3\u679c\u4e2d\u4f20\u9012\u53d8\u91cf\u6216\u8005\u53c2\u6570<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539yi_test.go\uff0c\u5c06Error\u4fee\u6539\u4e3aErrorf\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"316\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-3.jpg\" alt=\"\" class=\"wp-image-16744\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-3.jpg 694w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-3-300x137.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-3-600x273.jpg 600w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6253\u5370\u7ed3\u679c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"696\" height=\"157\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-4.jpg\" alt=\"\" class=\"wp-image-16746\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-4.jpg 696w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-4-300x68.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-4-600x135.jpg 600w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6d4b\u8bd5\u51fd\u6570\u6bd4\u8f83\u591a\uff0c\u6bcf\u4e2a\u90fd\u8c03\u7528t.Error\u6253\u5370\u5185\u5bb9\u4f1a\u51fa\u73b0\u91cd\u590d\u4ee3\u7801\uff0c\u6b64\u65f6\u53ef\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u6765\u51cf\u5c11\u4ee3\u7801\u91cd\u590d,\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"258\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/5-3.jpg\" alt=\"\" class=\"wp-image-16748\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/5-3.jpg 694w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/5-3-300x112.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/5-3-600x223.jpg 600w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u4e0a\u56fe\uff0c\u5355\u72ec\u5b9a\u4e49\u4e00\u4e2aerrorPrintf\u51fd\u6570\uff0c\u7136\u540e\u901a\u8fc7return\u8fd4\u56de\u7ed9t.Error()<\/p>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\uff1ago test\u547d\u4ee4\u53ea\u4f1a\u5904\u7406\u4ee5_test.go\u7ed3\u5c3e\u7684\u6587\u4ef6\uff0cgo build \u548c go install \u4e5f\u4f1a\u5ffd\u7565\u540d\u79f0\u4ee5_test.go\u7ed3\u5c3e\u7684\u6587\u4ef6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679cyi_test.go\u4e2d\u5305\u542b\u591a\u4e2a\u6d4b\u8bd5\u51fd\u6570\uff0c\u6b64\u65f6\u6307\u5411\u8fd0\u884c\u7279\u5b9a\u7684\u51fd\u6570\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u4f7f\u7528-run\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"131\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/6-4.jpg\" alt=\"\" class=\"wp-image-16751\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/6-4.jpg 695w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/6-4-300x57.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/6-4-600x113.jpg 600w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-run Abcd \u8868\u793a\u8fd0\u884c\u540d\u5b57\u4e2d\u5305\u542bAbcd\u7684\u51fd\u6570<\/li>\n\n\n\n<li>-v \u8868\u793a\u8f93\u51fa\u8be6\u7ec6\u4fe1\u606f\uff0c\u53ef\u4e0d\u52a0\uff0c\u52a0\u4e86\u66f4\u8be6\u7ec6<\/li>\n<\/ul>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\uff1a\u4e5f\u53ef\u4ee5\u4e0d\u7528\u6307\u5b9a\u6587\u4ef6\uff0c\u76f4\u63a5\u6267\u884c<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">go test -v -run Abcd<\/mark><\/strong>\u5373\u53ef<\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u591a\u51fd\u6570\u793a\u4f8b<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539yi_test.go\u6587\u4ef6\uff0c\u65b0\u589e\u4e00\u4e2aTestEfgh\u6d4b\u8bd5\u51fd\u6570\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"581\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/7-4.jpg\" alt=\"\" class=\"wp-image-16753\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/7-4.jpg 694w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/7-4-300x251.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/7-4-600x502.jpg 600w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9a\u4e49\u4e09\u4e2a\u5143\u7d20\u7684\u5207\u7247b<\/li>\n\n\n\n<li>\u671f\u671b\u503c\u4e3a\u524d\u4e24\u4e2a\u5143\u7d20\u9017\u53f7\u8fde\u63a5\uff0c\u7b2c\u4e09\u4e2a\u7684\u5143\u7d20\u7684and\u524d\u9762\u4e5f\u8981\u7528\u9017\u53f7<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u6d4b\u8bd5\uff0c\u67e5\u770b\u6267\u884c\u7ed3\u679c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"696\" height=\"237\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/9-3.jpg\" alt=\"\" class=\"wp-image-16755\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/9-3.jpg 696w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/9-3-300x102.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/9-3-600x204.jpg 600w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u56fe\u770b\u51fa\uff0c\u7b2c\u4e00\u4e2a\u51fd\u6570TestAbcd\u6d4b\u8bd5\u6210\u529f\uff0c\u7b2c\u4e8c\u4e2aTestEfgh\u6d4b\u8bd5\u5931\u8d25\uff0c\u56e0\u4e3a\u5b9e\u9645\u4e0e\u9884\u671f\u4e0d\u7b26\uff0c\u5c11\u4e86\u4e00\u4e2a\u9017\u53f7\uff0c\u8bf4\u660e\u6211\u4eec\u7684abcd()\u51fd\u6570\u53ea\u80fd\u7b26\u5408\u6ee1\u8db3\u4f20\u9012\u5305\u542b2\u4e2a\u5143\u7d20\u7684\u5207\u7247\uff0c\u4f20\u9012\u8d85\u8fc72\u4e2a\u5143\u7d20\u7684\u5207\u7247\u4e0d\u884c\uff0c\u6b64\u65f6\u9700\u8981\u4fee\u6539abcd\u51fd\u6570\uff0c\u8ba9\u5b83\u53ef\u4ee5\u6ee1\u8db32\u4e2a\u5143\u7d20\u548c2\u4e2a\u4ee5\u4e0a\u5143\u7d20\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"435\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/10-3.jpg\" alt=\"\" class=\"wp-image-16756\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/10-3.jpg 695w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/10-3-300x188.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/10-3-600x376.jpg 600w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u6b21\u8fd0\u884c\u6d4b\u8bd5\uff0c\u53ef\u4ee5\u53d1\u73b0\u4e24\u4e2a\u51fd\u6570\u90fd\u53ef\u4ee5\u6210\u529f\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"696\" height=\"168\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/11-1.jpg\" alt=\"\" class=\"wp-image-16757\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/11-1.jpg 696w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/11-1-300x72.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/11-1-600x145.jpg 600w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u8868\u9a71\u52a8\u6d4b\u8bd5<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u7684\u4e24\u4e2a\u6d4b\u8bd5\u51fd\u6570\u4e2d\u6709\u5f88\u591a\u91cd\u590d\u7684\u90e8\u5206\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"691\" height=\"286\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-5.jpg\" alt=\"\" class=\"wp-image-16760\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-5.jpg 691w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-5-300x124.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/1-5-600x248.jpg 600w\" sizes=\"auto, (max-width: 691px) 100vw, 691px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u9700\u8981\u7ef4\u62a4\u6bcf\u4e00\u4e2a\u5355\u72ec\u6d4b\u8bd5\u51fd\u6570\uff0c\u53ef\u4ee5\u6784\u5efa\u4e00\u4e2a\u7531\u8f93\u5165\u6570\u636e\u548c\u671f\u671b\u7684\u8f93\u51fa\u7ec4\u6210\u7684 &#8220;\u8868&#8221;\uff0c\u7136\u540e\u4f7f\u7528\u5355\u4e2a\u6d4b\u8bd5\u51fd\u6570\u68c0\u67e5\u8868\u4e2d\u7684\u6bcf\u4e00\u9879\uff0c\u8868\u6ca1\u6709\u6807\u51c6\u683c\u5f0f\uff0c\u5e38\u89c1\u7684\u7528\u6cd5\u662f\u5b9a\u4e49\u4e00\u4e2a\u65b0\u7684\u7ed3\u6784\u4f53\u7c7b\u578b\uff0c\u5b9a\u4e49\u4e00\u4e2alist\u5b57\u6bb5\u4fdd\u5b58\u8981\u4f20\u9012\u7ed9abcd\u7684\u5b57\u7b26\u4e32\u5207\u7247\uff0c\u4ee5\u53ca\u4e00\u4e2aexpected\u5b57\u6bb5\u4fdd\u5b58\u671f\u671b\u7684\u8fd4\u56de\u5b57\u7b26\u4e32<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"692\" height=\"107\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-5.jpg\" alt=\"\" class=\"wp-image-16762\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-5.jpg 692w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-5-300x46.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/2-5-600x93.jpg 600w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06TestAbcd()\u548cTestEfgh()\u53bb\u6389\uff0c\u53ea\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570TestOne()\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\u5207\u7247tests\uff0c\u6bcf\u4e2a\u5207\u7247\u90fd\u662f\u4e00\u4e2atestMethod\u7ed3\u6784\u4f53\uff0c\u7ed3\u6784\u4f53\u4e2dlist\u5b57\u6bb5\u5c31\u662f\u8981\u4f20\u9012\u7684\u5207\u7247\uff0c\u5faa\u73af\u904d\u5386\u7ed3\u6784\u4f53\u5207\u7247\uff0c\u5c06list\u5207\u7247\u4f20\u9012\u7ed9abcd()\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"640\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-4.jpg\" alt=\"\" class=\"wp-image-16764\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-4.jpg 695w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-4-300x276.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/3-4-600x553.jpg 600w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u66f4\u65b0\u540e\u7684\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\uff0c\u6267\u884cgo test\u6d4b\u8bd5\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"695\" height=\"132\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-5.jpg\" alt=\"\" class=\"wp-image-16766\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-5.jpg 695w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-5-300x57.jpg 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2024\/04\/4-5-600x114.jpg 600w\" sizes=\"auto, (max-width: 695px) 100vw, 695px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u540e\u7eed\u5982\u679c\u8981\u65b0\u589e\u4f20\u9012\u7684\u5207\u7247\u6570\u636e\uff0c\u53ea\u9700\u8981\u4fee\u6539tests\u5207\u7247\u5373\u53ef\uff0c\u7136\u540e\u6d4b\u8bd5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\uff1a\u5982\u679c\u8981\u6d4b\u8bd5\u7684\u51fd\u6570\u4e2d\u8fd8\u8c03\u7528\u4e86\u5176\u4ed6\u6587\u4ef6\u4e2d\u7684\u51fd\u6570\uff0c\u90a3\u4e48\u5728\u6267\u884cgo test\u7684\u65f6\u5019\uff0c\u76f4\u63a5\u6267\u884cgo test -v TestAbcd()\u540d\u5373\u53ef\u8fd0\u884c\u6307\u5b9a\u51fd\u6570(\u7b80\u5355\u5feb\u6377)\uff0c\u5982\u679c\u8981\u6307\u5b9a\u6587\u4ef6\uff0c\u90a3\u4e48\u9700\u8981\u52a0\u4e0a\u5168\u90e8\u6587\u4ef6\uff0c\u5426\u5219\u4f1a\u63d0\u793a\u51fd\u6570\u627e\u4e0d\u5230\uff0c\u5982\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">go test a_test.go a.go b.go c.go   \/\/\u628a\u76f8\u5173\u6587\u4ef6\u5168\u90e8\u52a0\u4e0a\u624d\u884c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48\u9700\u8981\u81ea\u52a8\u5316\u6d4b\u8bd5\uff1f golang\u63d0\u4f9b\u4e86\u4e00\u4e2atesting\u5305\u7528\u4e8e\u4e3a\u4ee3\u7801\u7f16\u5199\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0c\u8fd8\u6709go test \u547d [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":16714,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111,23],"tags":[],"class_list":["post-16713","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go","category-rong"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/16713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=16713"}],"version-history":[{"count":23,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/16713\/revisions"}],"predecessor-version":[{"id":16771,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/16713\/revisions\/16771"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/16714"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=16713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=16713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=16713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}