我需要在构建过程中运行GoConvey测试
如何确保go test
退出并显示错误退出代码(非0)?
答案 0 :(得分:2)
确定找到了错误:
我的代码中有TestMain,它在测试之前运行:
func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard) // Disable logs.
m.Run()
}
m.Run
应该用os.Exit
包装,以便可以将其与错误状态代码一起使用:
func TestMain(m *testing.M) {
log.SetOutput(ioutil.Discard) // Disable logs.
os.Exit(m.Run())
}
解决了问题
答案 1 :(得分:1)
您可以将goconvey作为普通测试运行,可以通过编写一个提供可预测结果的小型测试来非常简单地进行测试,例如
package c
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestConvey(t *testing.T){
Convey("TestConvey", t, func() {
So(false, ShouldBeTrue)
})
}
这应该是结果 xxx 14:44:03〜/ GO / src / c / c>进行测试 X 失败:
* /home/xxx/GO/src/c/c/a_test.go
Line 10:
Expected: true
Actual: false
1 total assertion
--- FAIL: TestConvey (0.00s)
FAIL
exit status 1
FAIL c/c 0.006s