blob: 696dda388209c94ca2ad4053cb8882c91df66f92 [file] [log] [blame]
bseenivadd66c362026-02-12 19:13:26 +05301// Copyright 2022 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Package gomock is a mock framework for Go.
16//
17// Standard usage:
18//
19// (1) Define an interface that you wish to mock.
20// type MyInterface interface {
21// SomeMethod(x int64, y string)
22// }
23// (2) Use mockgen to generate a mock from the interface.
24// (3) Use the mock in a test:
25// func TestMyThing(t *testing.T) {
26// mockCtrl := gomock.NewController(t)
27// mockObj := something.NewMockMyInterface(mockCtrl)
28// mockObj.EXPECT().SomeMethod(4, "blah")
29// // pass mockObj to a real object and play with it.
30// }
31//
32// By default, expected calls are not enforced to run in any particular order.
33// Call order dependency can be enforced by use of InOrder and/or Call.After.
34// Call.After can create more varied call order dependencies, but InOrder is
35// often more convenient.
36//
37// The following examples create equivalent call order dependencies.
38//
39// Example of using Call.After to chain expected call order:
40//
41// firstCall := mockObj.EXPECT().SomeMethod(1, "first")
42// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall)
43// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall)
44//
45// Example of using InOrder to declare expected call order:
46//
47// gomock.InOrder(
48// mockObj.EXPECT().SomeMethod(1, "first"),
49// mockObj.EXPECT().SomeMethod(2, "second"),
50// mockObj.EXPECT().SomeMethod(3, "third"),
51// )
52//
53// The standard TestReporter most users will pass to `NewController` is a
54// `*testing.T` from the context of the test. Note that this will use the
55// standard `t.Error` and `t.Fatal` methods to report what happened in the test.
56// In some cases this can leave your testing package in a weird state if global
57// state is used since `t.Fatal` is like calling panic in the middle of a
58// function. In these cases it is recommended that you pass in your own
59// `TestReporter`.
60package gomock