在使用 Ginkgo 框架编写测试时,我注意到按 Cc 终止正在运行的套件会产生误报。
当您查看代码时,您会注意到此测试应在 5 秒后失败。当我在 2 秒后终止它时,套件失败,但在结果中,有 1 个通过测试,0 个失败。
Debian Stretch 和 Ubuntu 18.04 上的 go 版本 1.11.4 和 1.12.4 的行为相同。
套件代码(使用自动生成ginkgo bootstrap
):
package hmmm_test
import (
"testing"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
func TestHmmm(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Hmmm Suite")
}
测试代码:
package hmmm_test
import (
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Hmmm", func() {
Context("Dummy test", func() {
It("should fail after 5 seconds", func() {
time.Sleep(5 * time.Second)
Expect(1).NotTo(Equal(1))
})
})
})
测试运行 5 秒时的输出(正确一个):
$ ginkgo
Running Suite: Hmmm Suite
=========================
Random Seed: 1555580607
Will run 1 of 1 specs
• Failure [5.001 seconds]
Hmmm
/tmp/hmmm/hmmm_test.go:10
Dummy test
/tmp/hmmm/hmmm_test.go:11
should fail after 5 seconds [It]
/tmp/hmmm/hmmm_test.go:12
Expected
<int>: 1
not to equal
<int>: 1
/tmp/hmmm/hmmm_test.go:14
------------------------------
Summarizing 1 Failure:
[Fail] Hmmm Dummy test [It] should fail after 5 seconds
/tmp/hmmm/hmmm_test.go:14
Ran 1 of 1 Specs in 5.002 seconds
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped
--- FAIL: TestHmmm (5.00s)
FAIL
Ginkgo ran 1 suite in 5.665592703s
Test Suite Failed
测试在完成之前终止时的输出(误报):
$ ginkgo
Running Suite: Hmmm Suite
=========================
Random Seed: 1555580763
Will run 1 of 1 specs
^C
Ran 1 of 1 Specs in 1.187 seconds
FAIL! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
Ginkgo ran 1 suite in 1.85541211s
Test Suite Failed
我希望输出类似于:
FAIL! -- 0 Passed | 1 Failed | 0 Pending | 0 Skipped
或 1 已跳过或挂起,但并不是Passed
特别是测试被写入失败。
实际输出表明失败,但所有测试...都通过了:
FAIL! -- 1 Passed | 0 Failed | 0 Pending | 0 Skipped
我错过了什么吗?