Skip to main content
Go’s standard testing package and net/http/httptest work seamlessly with Mizu. This guide shows patterns for testing handlers, middleware, and complete applications.

Testing handlers

Basic handler test

Testing JSON responses

Testing POST requests with JSON body

Table-driven tests

Use table-driven tests for thorough coverage:

Testing middleware

Test middleware in isolation

Testing with dependencies

Use interfaces for mocking

Testing error handling

Test helpers

Create reusable test helpers:
Usage:

Running tests

Best practices

  1. Test behavior, not implementation - Focus on what the handler does
  2. Use table-driven tests - Cover edge cases systematically
  3. Keep tests isolated - Each test creates its own app instance
  4. Use interfaces for dependencies - Makes mocking easy
  5. Test error paths - Ensure proper error responses
  6. Use meaningful test names - Describe what’s being tested

Next steps

Deployment

Deploy your tested app.

Project Structure

Organize code for testability.