1

我有以下Ginkgo测试文件:

package foo

import (
    "log"

    . "github.com/onsi/ginkgo"
)

var _ = BeforeSuite(func() {
    log.Print("BeforeSuite")
})

var _ = AfterSuite(func() {
    log.Print("AfterSuite")
})

var _ = Describe("Foo", func() {
    log.Print("Describe")
})

当我运行ginkgo -r -v时,测试文件运行,但BeforeSuiteandAfterSuite似乎没有:

2016/03/16 09:23:17 Describe
testing: warning: no tests to run
PASS

该行2016/03/16 09:23:17 Describe显示正在运行,但andDescribe的输出在哪里?BeforeSuiteAfterSuite

我并不真正关心输出,但在我的真实测试中(不是上面的片段),数据库构建和拆除没有得到执行。

我究竟做错了什么?

4

1 回答 1

4

你没有调用RunSpecs

func TestSo(t *testing.T) {
    RunSpecs(t, "My Test Suite")
}

输出然后看起来类似于

2016/03/16 07:16:05 Describe
Running Suite: So Suite
=======================
Random Seed: 1458137764
Will run 0 of 0 specs

2016/03/16 07:16:05 BeforeSuite
2016/03/16 07:16:05 AfterSuite

Ran 0 of 0 Specs in 0.000 seconds
SUCCESS! -- 0 Passed | 0 Failed | 0 Pending | 0 Skipped PASS

Ginkgo ran 1 suite in 1.211144437s
Test Suite Passed

您是否尝试在_suite_test.go文件中运行实际测试?

于 2016-03-16T14:18:51.603 回答