Go语言表组测试示例
2024-08-27 23:57:40
比基本测试多个循环。。。
package main import ( "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) } } } } }
最新文章
- iOS 阶段学习第十天笔记(字符串操作)
- 如何录制手机屏幕并转成gif
- WKWebView使用及注意点
- [luogu P2647] 最大收益(贪心+dp)
- <; %=...%>;<; %#... %>;<; % %>;<; %@ %>;具体意义
- Java_eclipse软件与git配合使用创建git仓库
- WPF跨程序集共享样式(跨程序集隔离样式和代码)
- erlang mnesia 数据库实现SQL查询
- HDU_2057——64位无符号16进制数的运算
- 常用几个UITableView,UICollectionView &#160;UIScrollView关键点
- 团队作业4——第一次项目冲刺(Alpha版本) 1
- git的CentOS服务端安装和windows客户端的使用
- Vue.js响应式原理
- ASP.NET Core2.2 IExceptionFilter
- 泊爷带你学go -- 反射的经典玩法
- Mac上通过iterm 上传文件到服务器
- 自学Zabbix11.3 Zabbix SNMP 常用OID列表
- 终端:Xcode模拟器上安装.app方法
- 《FPGA设计技巧与案例开发详解-第二版》全套资料包
- 学习笔记:Maven的ArcheType的学习笔记
热门文章
- 使用rsyslog编程,产生trace信息,记录到日志中
- 洛谷P3966 [TJOI2013]单词(fail树性质)
- Kubernetes - Getting Started With Kubeadm
- 第01篇 为什么推荐使用String直接赋值
- .NET类型转型的四种做法(转)
- hdu 4903 The only survival
- [Luogu 2590] ZJOI2008 树的统计
- 【NOIP】2016 换教室
- OPENId是什么, OAUTH 是什么
- nodejs入门教程之http的get和request简介及应用