1

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?

Community
  • 1
  • 1
Ralph
  • 31,584
  • 38
  • 145
  • 282

1 Answers1

4

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?

sberry
  • 128,281
  • 18
  • 138
  • 165
  • I had the `RunSpecs` in a separate `_suite_test.go` file, but it appears that for ginkgo to work, `"github.com/onsi/gomega"` must be imported in the file containing the `BeforeSuite`, ... . I had to add a fake `It` and `Expect` to allow this (the import would not be "used", otherwise. At least that is what further testing seems to indicate. Thanks. – Ralph Mar 16 '16 at 15:42