diff --git a/docs/index.md b/docs/index.md index 7eed27f1..7f54fd68 100644 --- a/docs/index.md +++ b/docs/index.md @@ -25,32 +25,25 @@ func getFromDB(db DB) string { } ``` -You can test `getFromDB` by either instantiating a testing database, or you can simply create a mock implementation of `DB` using mockery. Mockery can automatically generate a mock implementation that allows us to define assertions on how the mock was used, what to return, and other useful tidbits. We can add a `//go:generate` directive above our interface: - -```golang title="db.go" -//go:generate mockery --name DB -type DB interface { - Get(val string) string -} -``` +We can use simple configuration to generate a mock implementation for the interface: ```yaml title=".mockery.yaml" -inpackage: True # (1)! -with-expecter: True # (2)! -testonly: True # (3)! +with-expecter: True +packages: + github.com/org/repo: + interfaces: + DB: ``` -1. Generate our mocks next to the original interface -2. Create [expecter methods](features.md#expecter-structs) -3. Append `_test.go` to the filename so the mock object is not packaged - +