Skip to content

Tech stack: Go: Testing section #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ RustFMT
semver
Slackbot
subpackages
Subtests
TBD
TODO
unpatched
Expand Down
46 changes: 46 additions & 0 deletions docs/2_development/2_tech-stack/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,49 @@ jobs:
Make sure to pin the linter version (`version: v1.45`) since the same linters can behave differently from a version to another.
:::


## Testing

### Testing philosophy

Here are a few key points to remember when writing tests:

- your **production code must be testable**. Adjust it as needed.
- all your **tests must be event driven** and not time driven
- your **unit tests must be blazing fast**
- **never export testing code** across package boundaries
- run your unit and integration tests in **parallel**
- have a **good testing depth**: you need to assert enough affected elements
- **keep your tests dumb** and feel free to repeat code

### Libraries to use

- [github.com/stretchr/testify](https://github.com/stretchr/testify) for assertions
- [github.com/golang/gomock](https://github.com/golang/gomock) for mocking (see the [Mocking](#Mocking) section)

### `assert.*` vs `require.*`


### Asserting errors

- `assert.ErrorIs` + `assert.EqualError`


### 'Table' tests

### Subtests

### Parallel tests

- Network servers, listen on port `:0`.
- Race detector

### Unit tests

### Integration tests

### End to end tests

### Fuzz tests

### Continuous integration