{"id":164406,"date":"2020-10-06T23:19:30","date_gmt":"2020-10-06T15:19:30","guid":{"rendered":"http:\/\/4563.org\/?p=164406"},"modified":"2020-10-06T23:19:30","modified_gmt":"2020-10-06T15:19:30","slug":"go-%e7%9a%84%e6%b5%8b%e8%af%95%e8%b8%a9%e5%9d%91","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=164406","title":{"rendered":"Go \u7684\u6d4b\u8bd5\u8e29\u5751"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Go \u7684\u6d4b\u8bd5\u8e29\u5751               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysmood <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e00\u76f4\u5728\u7528 testify \u5199\u6d4b\u8bd5\uff0c\u5b83\u7b97\u662f\u6240\u6709\u6d4b\u8bd5\u5e93\u91cc\u9762\u6bd4\u8f83\u7b80\u5355\u53ef\u4f9d\u8d56\u7684\u3002\u7136\u800c\u5b83\u8fd8\u662f\u6709\u4e9b\u591a\u5e74\u6ca1\u89e3\u51b3\u7684\u95ee\u9898\u3002\u6bd4\u5982\u6bd4\u8f83\u65f6\u95f4\u7684\u5927\u5c0f\uff08 v2 \u624d\u652f\u6301\u4e86\uff0c\u8fd8\u5728\u5f00\u53d1\u4e2d\uff09\u3002<\/p>\n<p>\u6bd4\u5982\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u770b\u4e0a\u53bb\u5f88\u6b63\u5e38\uff0c\u4f46\u662f\u5176\u5b9e\u4f1a\u89e6\u53d1 testify \u7684 bug:<\/p>\n<pre><code>import (  \"testing\"   \"github.com\/stretchr\/testify\/suite\" )  func Test(t *testing.T) {  suite.Run(t, &amp;Suite{}) }  type Suite struct {  suite.Suite }  func (s *Suite) TestA() {  s.T().Parallel()  s.Equal(2, 1) }  func (s *Suite) TestB() {  s.T().Parallel() } <\/code><\/pre>\n<p>\u5177\u4f53\u7684\u8ba8\u8bba\u53ef\u4ee5\u770b\u8fd9\u91cc\uff1a https:\/\/github.com\/stretchr\/testify\/issues\/187<\/p>\n<p>testify \u4e4b\u6240\u4ee5\u6709\u8fd9\u4e2a\u95ee\u9898\uff0c\u6838\u5fc3\u539f\u56e0\u662f\u5b83\u7684\u8bbe\u8ba1\u4f1a\u5bfc\u81f4 Suite \u5728\u591a\u4e2a\u5b50\u6d4b\u8bd5\u4e2d\u88ab\u7ade\u4e89\u3002 \u4e3a\u4e86\u5904\u7406\u8fd9\u4e2a\u95ee\u9898\u5199\u4e86\u4e2a\u8f7b\u91cf\u7684\u5e93\uff0c\u65e0\u4efb\u4f55\u4f9d\u8d56\u53ef\u4ee5\u7528\u6765\u66ff\u4ee3 testify \u7684 suite\uff0c\u914d\u5408 testify \u7684 assert \u7684\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>import (  \"testing\"  \"time\"   \"github.com\/stretchr\/testify\/assert\"  \"github.com\/ysmood\/got\" )  func Test(t *testing.T) {  got.Each(t, beforeEach) }  func beforeEach(t *testing.T) Suite {  t.Parallel()  return Suite{assert.New(t)} }  type Suite struct { \/\/ struct that holds subtests  *assert.Assertions }  func (s Suite) A() { \/\/ test case A  time.Sleep(time.Second)  s.Equal(1, 1) }  func (s Suite) B() { \/\/ test case B  time.Sleep(time.Second)  s.Equal(2, 1) } <\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u72ec\u7acb\u4f7f\u7528\uff0c\u7528\u6765\u505a\u4e00\u4e9b\u7b80\u5355\u7684\u6d4b\u8bd5\u5e94\u8be5\u4f1a\u5f88\u987a\u624b\uff0c\u4e0d\u9700\u8981\u5199\u4e00\u5806 <code>Test<\/code> \u524d\u7f00\u548c <code>t *testing.T<\/code> \u4e86\uff1a<\/p>\n<pre><code>import (  \"testing\"   \"github.com\/ysmood\/got\" )  func Test(t *testing.T) {  got.Each(t, S{}) }  type S struct {  got.Assertion }  func (s S) A() {  s.Eq(1, 1) }  func (s S) B() {  s.Gt(2, 1) } <\/code><\/pre>\n<p>\u9879\u76ee\u5730\u5740\uff1a https:\/\/github.com\/ysmood\/got<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3606318\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pwli <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6ca1\u6709\u770b\u592a\u61c2\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3606319\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : ysmood <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @pwli \u5177\u4f53\u7684\u8ba8\u8bba\u770b\u8fd9\u4e2a https:\/\/github.com\/stretchr\/testify\/issues\/187                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Go \u7684\u6d4b\u8bd5\u8e29\u5751 \u8cc7\u6df1\u5927\u4f6c : y&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/164406"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=164406"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/164406\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=164406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=164406"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=164406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}