首页 > 代码库 > Go语言表组测试示例
Go语言表组测试示例
比基本测试多个循环。。。
package mainimport ( "testing" "net/http")const checkMark = " OK! "const ballotX = " ERROR! " func TestDownload(t *testing.T) { var urls = []struct { url string statusCode int }{ { "http://localhost:8000/test.html", http.StatusOK, }, { "http://localhost:8000/test.html2", http.StatusNotFound, }, } t.Log("Given the need to test downloading content.") { for _, u := range urls { t.Logf("\tWhen checking \"%s\" for status code \"%d\"", u.url, u.statusCode) { resp, err := http.Get(u.url) if err != nil { t.Fatal("\tShould be able to make the Get call.", ballotX, err) } t.Log("\t\tShould be able to make the Get call.", checkMark) defer resp.Body.Close() if resp.StatusCode == u.statusCode { t.Logf("\t\tShould receive a \"%d\" status, %v", u.statusCode, checkMark) } else { t.Errorf("\t\tShould receive a \"%d\" status. %v %v", u.statusCode, ballotX, resp.StatusCode) } } } }}
Go语言表组测试示例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。