Go convention pack TC-001/TC-002 says stdlib-only testing, but 72% of test files use testify #6184
Replies: 2 comments
|
Hello! Sorry for the late response, I don't see |
|
Hey @rh-hemartin, apologies, the That said, the testify usage data itself is real: ~72% of test files use assert/require, and docs/contributing/go-code.md already documents the require-vs-assert goroutine rule from #5675. I have updated the discussion accordingly. If it would be useful to explicitly document testify as the project's preferred assertion style in the contributing guide (so new contributors don't have to guess), I'm happy to open a PR for that. Otherwise feel free to close this. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Observation
A scan of all 216
_test.gofiles in the project shows:assert+require)assertonly)requireonly)33 packages use testify exclusively, 14 use stdlib exclusively, and 13 are mixed. The canonical pattern is importing both
testify/assertandtestify/requiretogether.Question
assert + requireis clearly the de facto testing convention, and docs/contributing/go-code.md already documents testify-specific guidance (the require-vs-assert goroutine rule). But there's no explicit statement anywhere that testify is the preferred assertion style for new test code.Would it be useful to add a short note to the contributing guide making this explicit? Something like:
"Use testify/assert and testify/require for assertions. Use require for preconditions that should abort the test on failure; use assert everywhere else. Inside goroutines spawned by a test, always use assert (never require), see the goroutine rule below."
This would help new contributors know to reach for testify instead of raw
t.Errorf/t.Fatalf, without having to infer it from existing code.Context
testify/mockortestify/suiteusage exists anywhere, onlyassertandrequiredocs/contributing/go-code.mdalready documents testify-specific guidance (the goroutinerequirevsassertrule from Add testify require-vs-assert goroutine rule to Go contributing guide #5675)internal/poll,internal/repos,cmd/mint) that appear to predate the testify conventionThis could be a good first contribution for an external contributor — update the pack rules and add a note in the contributing guide.
All reactions