Search code examples
goginkgogomega

Ginkgo tests not being found?


I do not understand why 'go' cannot find my Ginkgo test files

Here's how my structure looks:

events
├── button_not_shown_event.go
├── events_test
│   └── button_not_shown_event_test.go

And here how my button_not_shown_event_test.go look like

package events_test

import (
    "fmt"
    . "github.com/onsi/ginkgo"
    . "github.com/onsi/gomega"
)

var _ = Describe("ButtonNotShownEvent", func() {
  BeforeEach(func() {
    Expect(false).To(BeTrue())
  })
  
  Context("ButtonNotShownEvent.GET()", func() {
        It("should not return a JSONify string", func() {
           Expect(true).To(BeFalse())
        })
    })
})

Notice I have specifically written a test so that it will fail.

But every time I run the Ginkgo test I get the following error

go test ./app/events/events_test/button_not_shown_event_test.go  -v

testing: warning: no tests to run
PASS
ok      command-line-arguments  1.027s

So clearly there is something I'm missing over here.

Any clue?


Solution

  • You have a few issues.

    1. You aren't importing the testing package. This should be in the bootstrap file generated by Ginkgo.
    2. The bootstrap file should also include as a parameter the testing.T function. e.g. (t *testing.T).
    3. It looks like you skipped a step or two in the Ginkgo process, resulting in a prior dependency not existing. e.g. the bootstrap/stub.

    Additionally, after a lot of comments by several people. You likely need to read the Ginkgo docs, to be sure you are following their process properly to get your tests setup properly.