Go API testing patterns -- httptest setup, table-driven tests with subtests, test helpers, middleware testing, dependency injection with interfaces, database isolation, parallel tests, testify assertions, golden files
98
98%
Does it follow best practices?
Impact
99%
1.06xAverage score across 5 eval scenarios
Passed
No known issues
Memory SQLite per test
100%
100%
Migrations in setup
100%
100%
setupTestDB helper with t.Helper
100%
100%
t.Cleanup for DB close
100%
100%
Tests are independent
100%
100%
Create task test
100%
100%
Create then fetch test
100%
60%
Status update test
100%
100%
Error paths tested
100%
100%
Table-driven with t.Run
33%
100%
Interface defined
100%
100%
Handler accepts interface
100%
100%
Mock in _test.go
100%
100%
Mock has configurable error
100%
100%
Success scenario tested
100%
100%
Failure scenario returns 503
100%
100%
No gomock or mockery
100%
100%
httptest used
100%
100%
Validation error tested
100%
100%
t.Helper in helpers
100%
100%
User not found tested
100%
100%
Middleware tested in isolation
100%
100%
No-token returns 401
100%
100%
Invalid token returns 401
100%
100%
Expired token returns 401
100%
100%
Valid token passes through
100%
100%
Table-driven with t.Run
100%
100%
Protected endpoint integration test
100%
100%
httptest used
75%
100%
t.Helper in helpers
100%
100%
Health endpoint unprotected
0%
100%
Dummy handler verifies context
100%
100%
Test table struct slice
100%
100%
t.Run subtests
100%
100%
Missing name validation
100%
100%
Invalid price validation
100%
100%
Invalid category validation
100%
100%
Missing category validation
100%
100%
Empty body validation
66%
100%
Valid case included
100%
100%
Error body asserted
100%
100%
httptest used
87%
100%
State reset between tests
100%
100%
Test helper with t.Helper
100%
100%
httptest used
100%
100%
memory SQLite
100%
100%
makeRequest helper with t.Helper
100%
100%
createTestUser helper
100%
100%
table-driven test with t.Run
0%
100%
GET list test
100%
100%
POST create test
100%
100%
GET by ID test
100%
100%
create-then-fetch persistence
100%
100%
404 for nonexistent user
100%
100%
400 for invalid input
100%
100%
response body shape asserted
100%
100%
password not in response
0%
100%