Skip to content
This repository

Question: Is it possible to reference testing.T in the tests? #9

Closed
adamstep opened this Issue October 12, 2013 · 10 comments

4 participants

Adam Stepinski Onsi Fakhouri Bryan Goldstein Lasana Murray
Adam Stepinski

Is it possible to reference testing.T in the tests? This is needed by gomock to create a new mock controller.

Onsi Fakhouri
Owner
Onsi Fakhouri
Owner
Adam Stepinski

Thanks, I'll try it out and let you know how it goes!

Adam Stepinski

It works! The test suite continues to run even after the first test fails. Thanks again for the suggestion, we're planning to move all of our tests from gobdd to Ginkgo to take advantage of the extra features.

type GinkgoTestReporter struct {}

func (g GinkgoTestReporter) Errorf(format string, args ...interface{}) {
    Fail(fmt.Sprintf(format, args))
}

func (g GinkgoTestReporter) Fatalf(format string, args ...interface{}) {
    Fail(fmt.Sprintf(format, args))
}

var _ = Describe("Handler", func() {
    var (
        t GinkgoTestReporter
        mockCtrl *gomock.Controller
        mockDatabase *models.MockDatabase
        handler *Handler
    )

    BeforeEach(func() {
        mockCtrl = gomock.NewController(t)
        mockDatabaseModel = models.NewMockDatabase(mockCtrl)
        handler = NewHandler(mockDatabase)
    })

    AfterEach(func() {
        mockCtrl.Finish()
    })

    // It() calls here
})
Onsi Fakhouri
Owner
Bryan Goldstein

In the mean time I dumped the above example into a package here.

Onsi Fakhouri
Owner

Thanks for the nudge brysgo :) I finally got around to this. I've implemented a simple Gomock test reporter under github.com/onsi/ginkgo/thirdparty/gomocktestreporter and updated the docs with usage details.

@brysgo I liked the fact that you added a NewController method -- seems convenient -- but I didn't do the same to avoid giving Ginkgo a direct dependency on gomock.

Any feedback appreciated, as always :)

Onsi Fakhouri onsi closed this November 17, 2013
Bryan Goldstein

Works great! Just added it to my project.

Onsi Fakhouri
Owner

Sweet. Thanks @brysgo

Lasana Murray

I saw this today, in case anyone doubts, it works and it works well. :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.