Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit bbc35b5

Browse files
authored
add some docs on default TestReporter behavior (#610)
Fixes: #158
1 parent 96d9cb5 commit bbc35b5

File tree

2 files changed

+59
-38
lines changed

2 files changed

+59
-38
lines changed

gomock/controller.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

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-
// defer mockCtrl.Finish()
27-
//
28-
// mockObj := something.NewMockMyInterface(mockCtrl)
29-
// mockObj.EXPECT().SomeMethod(4, "blah")
30-
// // pass mockObj to a real object and play with it.
31-
// }
32-
//
33-
// By default, expected calls are not enforced to run in any particular order.
34-
// Call order dependency can be enforced by use of InOrder and/or Call.After.
35-
// Call.After can create more varied call order dependencies, but InOrder is
36-
// often more convenient.
37-
//
38-
// The following examples create equivalent call order dependencies.
39-
//
40-
// Example of using Call.After to chain expected call order:
41-
//
42-
// firstCall := mockObj.EXPECT().SomeMethod(1, "first")
43-
// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall)
44-
// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall)
45-
//
46-
// Example of using InOrder to declare expected call order:
47-
//
48-
// gomock.InOrder(
49-
// mockObj.EXPECT().SomeMethod(1, "first"),
50-
// mockObj.EXPECT().SomeMethod(2, "second"),
51-
// mockObj.EXPECT().SomeMethod(3, "third"),
52-
// )
5315
package gomock
5416

5517
import (

gomock/doc.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)