CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/go-api-testing

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

1.06x
Quality

98%

Does it follow best practices?

Impact

99%

1.06x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

Evaluation results

96%

2%

Write Tests for a Go Task API with Database Isolation

Criteria
Without context
With context

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%

100%

Write Tests Using Interface-Based Dependency Injection for a Go Notification Service

Criteria
Without context
With context

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%

100%

7%

Write Tests for Go Authentication Middleware

Criteria
Without context
With context

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%

100%

3%

Write Table-Driven Validation Tests for a Go Product API

Criteria
Without context
With context

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%

100%

18%

Write Tests for a Go User Management API

Criteria
Without context
With context

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%

Evaluated
Agent
Claude Code
Model
Claude Sonnet 4.6

Table of Contents