当前位置:网站首页>Go learning --- unit test subtest
Go learning --- unit test subtest
2022-07-01 03:50:00 【Yaya boss】
One 、 Unit test subtest
package subtest
// Define a function
func Add(a,b int) int {
return a + b
}
func Sum(a,b int) int {
return a * b
}
package subtest
import "testing"
// Subtest
func TestSum(t *testing.T) {
t.Run("ping", func(t *testing.T) {
if Sum(2,5) != 10 {
t.Fatal("fail")
}
})
t.Run("dog", func(t *testing.T) {
if Sum(2,-5) != -10 {
t.Fatal("fail")
}
})
}
// Batch subtest
func TestAdd(t *testing.T) {
ces := []struct{
Name string
A int
B int
Fruit int
}{
{"A",1,2,3},
{"B",3,2,5},
{"C",6 ,6,12},
}
for _, ce := range ces {
t.Run(ce.Name, func(t *testing.T) {
ans := Add(ce.A,ce.B)
if ans != ce.Fruit {
t.Fatal(ce.Name,ce.A,ce.B,ce.Fruit)
}
})
}
}
边栏推荐
- [TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation
- Blueprism registration, download and install -rpa Chapter 1
- 复习专栏之---消息队列
- 30. Concatenate substrings of all words
- PageObject模式解析及案例
- C语言的sem_t变量类型
- 6. Z 字形变换
- Millet College wechat scanning code login process record and bug resolution
- Valentine's Day is nothing.
- 10. regular expression matching
猜你喜欢
随机推荐
访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
Deep learning | rnn/lstm of naturallanguageprocessing
4. [WebGIS practice] software operation chapter - data import and processing
5. [WebGIS practice] software operation - service release and permission management
392. 判断子序列
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
6. zigzag transformation
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
Sort linked list (merge sort)
You cannot right-click F12 to view the source code solution on the web page
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
187. repeated DNA sequences
165. compare version numbers
MFC window scroll bar usage
168. excel table column name
187. 重复的DNA序列
在 C 中声明函数之前调用函数会发生什么?
205. isomorphic string
241. 为运算表达式设计优先级








