Golang Ginkgo的BeforeSuite没有输出。

huangapple go评论153阅读模式
英文:

No output from Golang Ginkgo BeforeSuite

问题

我有以下的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时,测试文件会运行,但是BeforeSuiteAfterSuite似乎没有出现:

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

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

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

我做错了什么?

英文:

I have the following Ginkgo test file:

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")
})

When I run ginkgo -r -v, the test file runs, but the BeforeSuite and AfterSuite do not appear to:

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

The line 2016/03/16 09:23:17 Describe shows that the Describe is running, but where is the output for BeforeSuite and AfterSuite?

I do not really care about the output, but in my real test (not the fragment above), database build up and tear down are not getting executed.

What am I doing wrong?

答案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文件中运行实际的测试?

英文:

You are not invoking RunSpecs

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

Output then appears similar to

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

Are you trying to run your actual tests in the _suite_test.go file?

huangapple
  • 本文由 发表于 2016年3月16日 21:35:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/36037244.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定