Skip to content

Instantly share code, notes, and snippets.

@vladlosev
Last active February 15, 2016 19:58
Show Gist options
  • Save vladlosev/fad989f51776c2061d72 to your computer and use it in GitHub Desktop.
Save vladlosev/fad989f51776c2061d72 to your computer and use it in GitHub Desktop.
Test for .Times(0) functionality in github.com/stretchr/mock
package mock
import (
"errors"
"testing"
)
type TestInterface interface {
TestMethod(a, b, c int) (int, error)
}
type TestImplementation struct {
Mock
}
func (i *TestImplementation) TestMethod(a, b, c int) (int, error) {
args := i.Called(a, b, c)
return args.Int(0), errors.New("Whoops")
}
func TestTimesZeroNoCalls(t *testing.T) {
var mockedService = new(TestImplementation)
mockedService.On("TestMethod").Return(5, 6, 7).Times(0)
mockedService.AssertExpectations(t)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment