LiteIDE 编写Go的单元测试
生活随笔
收集整理的這篇文章主要介紹了
LiteIDE 编写Go的单元测试
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
第一步:新建一個 package ?"even"
第二步:編寫代碼
// even project even.go package evenfunc Even(i int)bool{return i%2==0 }func odd(i int)bool{return i%2==1 }第三步:在包 even 下新建測試文件 even_test.go
第四步:編寫測試代碼
// even_test package evenimport ("testing" )func TestEven(t *testing.T){if !Even(2){t.Log("2 should be even")t.Fail()} }func TestOdd(t *testing.T){if !odd(2){t.Log("2 should not be odd")t.Fail()} }注意: 即使函數(shù) odd 首寫字母為小寫,但是在測試文件中依然要寫成 TestOdd !!!
第五步:運行測試
總結(jié)
以上是生活随笔為你收集整理的LiteIDE 编写Go的单元测试的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 相互引用的初始化过程
- 下一篇: 软件系统架构~视点和视图