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
{
"context": "Tests whether the agent refactors a Go API to use interface-based dependency injection, creates a hand-written mock in _test.go, injects it into handlers, and tests both success and error (service unavailable) scenarios.",
"type": "weighted_checklist",
"checklist": [
{
"name": "Interface defined",
"description": "An EmailSender (or similar) interface is defined with a Send method signature that both the real and mock implementations satisfy",
"max_score": 15
},
{
"name": "Handler accepts interface",
"description": "The notification handler (or setupRoutes) accepts the interface type, not the concrete *RealEmailSender type",
"max_score": 12
},
{
"name": "Mock in _test.go",
"description": "A mock/fake struct that implements the EmailSender interface is defined in a _test.go file, not in production code",
"max_score": 12
},
{
"name": "Mock has configurable error",
"description": "The mock struct has a field (e.g., err error or shouldFail bool) that lets tests configure whether Send returns an error",
"max_score": 10
},
{
"name": "Success scenario tested",
"description": "There is a test where the mock returns nil (success) and the notification is created with status 201",
"max_score": 10
},
{
"name": "Failure scenario returns 503",
"description": "There is a test where the mock returns an error (simulating email service down) and the API returns 503 (Service Unavailable) rather than 500",
"max_score": 12
},
{
"name": "No gomock or mockery",
"description": "The mock is hand-written (a simple struct with methods), not generated by gomock, mockery, or similar code generation tools",
"max_score": 8
},
{
"name": "httptest used",
"description": "Tests use httptest.NewRequest and httptest.NewRecorder, not real HTTP calls",
"max_score": 8
},
{
"name": "Validation error tested",
"description": "There is a test for sending a notification with missing/invalid fields expecting 400",
"max_score": 5
},
{
"name": "t.Helper in helpers",
"description": "Test helper functions call t.Helper()",
"max_score": 5
},
{
"name": "User not found tested",
"description": "There is a test for sending a notification to a nonexistent user expecting 404",
"max_score": 3
}
]
}