code.vegaprotocol.io/vega@v0.79.0/TESTING.md (about) 1 We use `mockgen`, from [`golang/mock`](https://github.com/golang/mock). 2 3 ## Generating/updating mock files 4 5 ```bash 6 # Note: this may take over a minute, with no output. 7 make mocks 8 ``` 9 10 The Makefile target runs `go generate`, which looks for comments of the form 11 `//go:generate`. 12 13 Because these comments have `go run github.com/golang/mock/mockgen` as the 14 command, there is no need to run `go get` or `go install` to fetch or install 15 `mockgen`. 16 17 ## Example 18 19 The file `candles/service.go` has: 20 21 ```go 22 //go:generate go run github.com/golang/mock/mockgen -destination mocks/candle_store_mock.go -package mocks code.vegaprotocol.io/vega/candles CandleStore 23 type CandleStore interface { /* ... */ } 24 ``` 25 26 In order to recreate just the candle mocks: 27 28 ```bash 29 cd .../go/src/vega/candles # trading-core 30 rm -rf mocks 31 go generate . 32 git diff # hopefully no differences 33 ``` 34 35 ## Running tests 36 37 To run all tests, use: 38 39 ```bash 40 make test 41 ``` 42 43 To run tests from one subdirectory, use: 44 45 ```bash 46 go test ./somedir/ 47 ``` 48 49 To force a re-run of previously successful tests, add `-count 1`. 50 51 ## Reasons for moving from `mockery` to `mockgen` 52 53 TBD (#230)