|
| 1 | +// 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 | +// (1) Define an interface that you wish to mock. |
| 19 | +// type MyInterface interface { |
| 20 | +// SomeMethod(x int64, y string) |
| 21 | +// } |
| 22 | +// (2) Use mockgen to generate a mock from the interface. |
| 23 | +// (3) Use the mock in a test: |
| 24 | +// func TestMyThing(t *testing.T) { |
| 25 | +// mockCtrl := gomock.NewController(t)// |
| 26 | +// mockObj := something.NewMockMyInterface(mockCtrl) |
| 27 | +// mockObj.EXPECT().SomeMethod(4, "blah") |
| 28 | +// // pass mockObj to a real object and play with it. |
| 29 | +// } |
| 30 | +// |
| 31 | +// By default, expected calls are not enforced to run in any particular order. |
| 32 | +// Call order dependency can be enforced by use of InOrder and/or Call.After. |
| 33 | +// Call.After can create more varied call order dependencies, but InOrder is |
| 34 | +// often more convenient. |
| 35 | +// |
| 36 | +// The following examples create equivalent call order dependencies. |
| 37 | +// |
| 38 | +// Example of using Call.After to chain expected call order: |
| 39 | +// |
| 40 | +// firstCall := mockObj.EXPECT().SomeMethod(1, "first") |
| 41 | +// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall) |
| 42 | +// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall) |
| 43 | +// |
| 44 | +// Example of using InOrder to declare expected call order: |
| 45 | +// |
| 46 | +// gomock.InOrder( |
| 47 | +// mockObj.EXPECT().SomeMethod(1, "first"), |
| 48 | +// mockObj.EXPECT().SomeMethod(2, "second"), |
| 49 | +// mockObj.EXPECT().SomeMethod(3, "third"), |
| 50 | +// ) |
| 51 | +// |
| 52 | +// The standard TestReporter most users will pass to `NewController` is a |
| 53 | +// `*testing.T` from the context of the test. Note that this will use the |
| 54 | +// standard `t.Error` and `t.Fatal` methods to report what happened in the test. |
| 55 | +// In some cases this can leave your testing package in a weird state if global |
| 56 | +// state is used since `t.Fatal` is like calling panic in the middle of a |
| 57 | +// function. In these cases it is recommended that you pass in your own |
| 58 | +// `TestReporter`. |
| 59 | +package gomock |
0 commit comments