Пример #1
0
func Test_Mock_On_WithFuncPanics(t *testing.T) {
	// make a test impl object
	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	assert.Panics(t, func() {
		mockedService.On("TheExampleMethodFunc", func(string) error { return nil })
	})
}
Пример #2
0
func Test_Mock_Called_Unexpected(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	// make sure it panics if no expectation was made
	assert.Panics(t, func() {
		mockedService.Called(1, 2, 3)
	}, "Calling unexpected method should panic")

}
Пример #3
0
func Test_Mock_Called_For_SetTime_Expectation(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	mockedService.On("TheExampleMethod", 1, 2, 3).Return(5, "6", true).Times(4)

	mockedService.TheExampleMethod(1, 2, 3)
	mockedService.TheExampleMethod(1, 2, 3)
	mockedService.TheExampleMethod(1, 2, 3)
	mockedService.TheExampleMethod(1, 2, 3)
	assert.Panics(t, func() {
		mockedService.TheExampleMethod(1, 2, 3)
	})

}
Пример #4
0
func Test_Mock_On_WithVariadicFuncWithInterface(t *testing.T) {

	// make a test impl object
	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	assert.Equal(t, mockedService.On("TheExampleMethodVariadicInterface", []interface{}{1, 2, 3}).Return(nil), &mockedService.Mock)
	assert.Equal(t, "TheExampleMethodVariadicInterface", mockedService.onMethodName)
	assert.Equal(t, []interface{}{1, 2, 3}, mockedService.onMethodArguments[0])

	assert.NotPanics(t, func() {
		mockedService.TheExampleMethodVariadicInterface(1, 2, 3)
	})
	assert.Panics(t, func() {
		mockedService.TheExampleMethodVariadicInterface(1, 2)
	})

}
Пример #5
0
// Panics asserts that the code inside the specified PanicTestFunc panics.
//
//   require.Panics(t, func(){
//     GoCrazy()
//   }, "Calling GoCrazy() should panic")
func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) {
	if !assert.Panics(t, f, msgAndArgs...) {
		t.FailNow()
	}
}