diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-10-10 14:11:54 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-10-14 13:44:55 +0300 |
commit | a53853a7668a3e12c2d22a1d8009678077be3801 (patch) | |
tree | 89a2d110f04b6a5fa373b697aca71f0b18cef026 | |
parent | 1881ab188e2789715ad1307fb1748d6c14e72474 (diff) |
STYLE.md: Document argument order of `testing.TB` and `context.Context`
Document the order of arguments that we use in this project to be
`testing.TB` first, `context.Context` second to make this discoverable.
While at it also document our use of `t.Helper()`.
-rw-r--r-- | STYLE.md | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -194,6 +194,19 @@ func TestT_M_suffix() { ... } func TestT_M_suffixWithMultipleWords() { ... } ``` +### Test helpers + +Helper functions for test helpers should be clearly marked with `t.Helper()` so +that stack traces become more usable. `testing.TB` arguments should always be +passed as first parameter, followed by `context.Context` if required. + +```go +func testHelper(tb testing.TB, ctx context.Context) { + tb.Helper() + ... +} +``` + ### Table-driven tests We like table-driven tests ([Table-driven tests using subtests](https://blog.golang.org/subtests#TOC_4.), [Cheney blog post], [Golang wiki]). |