moconvey is a package that aims to better integrate the mocks of stretchr/testify and the testing framework that is goconvey
This package currently defines all of the assertions provided by the mock struct as convey style assertions so you will still be able to get those fancy green check marks for your mock assertions too.
This package was originally designed to work with mocks generated by mockery but should work with any mock using testify's mock package
Here is an example test function testing a piece of code that operates on a mock called Foo
.
The test function can setup expectations (testify) for Foo
and assert that they indeed happened:
package convey
import (
"testing"
. "github.com/tamccall/moconvey/assertions"
. "github.com/smartystreets/goconvey/convey"
"github.com/tamccall/moconvey/mocks"
)
func TestExampleMock(t *testing.T) {
Convey( "Given the example mock" , t, func() {
mock := new(mocks.Foo)
mock.On("Bar").Return("Hello World")
Convey("When Bar is called", func() {
mock.Bar()
Convey("Assert Bar is called", func() {
So(mock, ShouldHaveReceived, "Bar")
})
})
})
}