Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

docs: add mocking info to unit testing guide #1666

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/development_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ you will find the per-function analysis useful. This will show you code paths th

![per function](./images/unit-test-coverage-3.png)

##### Mocking

OSM uses the [GoMock](https://github.com/golang/mock) mocking framework to mock interfaces in unit tests.
GoMock's `mockgen` tool is used to autogenerate mocks from interfaces.

As an example, to create a mock client for the `Configurator` interface defined in the [configurator](/pkg/configurator) package:
```bash
mockgen -destination=pkg/configurator/mock_client.go -package=configurator github.com/openservicemesh/osm/pkg/configurator Configurator
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you either add to this PR or follow up with a change to include this package in tools.go at the root of the repo and update the instructions to use go run ... to invoke the generator? That way we can track the version we're using and there's no extra step required to get the mockgen binary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in a follow-up.


When a mocked interface is changed, the autogenerated mock code must be regenerated.
More details can be found in [GoMock's documentation](https://github.com/golang/mock/blob/master/README.md).

#### Integration Tests

Unit tests focus on a single function. These ensure that with a specific input, the function
Expand Down