在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
可以使用Go实现自动化测试,EdgeX中也使用了大量的test代码 1、在工程里新建一个Test目录,创建一个文件testtestify_test.go,必须以_test结尾,代码如下 package Test import ( "fmt" "testing" "github.com/stretchr/testify/assert" ) // 计算并返回 x + 2. func Calculate(x int) (result int) { result = x + 2 return result } func TestCalculate1(t *testing.T) { assert.Equal(t, Calculate(2), 4) } func main() { fmt.Println("Hello World") } func TestCalculate2(t *testing.T) { assert := assert.New(t) var tests = []struct { input int expected int }{ {2, 4}, {-1, 1}, {0, 2}, {-5, -3}, {99999, 100001}, } for _, test := range tests { assert.Equal(Calculate(test.input), test.expected) } } 2、进入目录,执行 C:\Users\zgj\Desktop\GoStudy\Test>go test PASS ok github.com/tarm/Test 1.424s C:\Users\zgj\Desktop\GoStudy\Test>go test -v === RUN TestCalculate1 --- PASS: TestCalculate1 (0.00s) === RUN TestCalculate2 --- PASS: TestCalculate2 (0.00s) PASS ok github.com/tarm/Test 0.522s 3、带-v参数会详细显示测试过程,如果与预期不一致。
|
请发表评论