Golang Testing Standards
Priority: P0 (CRITICAL)
Principles
Guidelines
TDD Workflow
-
Red: Write a failing table-driven test case.
-
Green: Implement logic to pass.
-
Refactor: Simplify code.
Golden Snippet
See Table-Driven Tests for full template.
Tools
-
Stdlib: testing package is usually enough.
-
Testify (stretchr/testify ): Assertions (assert , require ) and Mocks.
-
Mockery: Auto-generate mocks for interfaces.
-
GoMock: Another popular mocking framework.
Naming
-
Test file: *_test.go
-
Test function: func TestName(t *testing.T)
-
Example function: func ExampleName()
Anti-Patterns
-
Sleeping in tests: Use channels/waitgroups or retry logic.
-
Testing implementation details: Test public behavior/interface.
References
-
Table-Driven Tests
-
Mocking Strategies