Skip to content

Create Comprehensive Test Template #15

Description

@frankbria

Summary

Provide a reference test template that demonstrates best practices for AI agents to follow when writing tests.

Goal

AI agents need concrete examples of:

  • Traditional unit tests
  • Property-based tests with Hypothesis
  • Parametrized tests
  • Integration tests
  • Proper fixture usage

Tasks

1. Create Template File

  • Create tests/test_template.py
  • Add comprehensive docstrings
  • Include multiple testing patterns
  • Show Hypothesis integration

2. Test Pattern Examples

  • Specific known cases
  • Error handling tests
  • Fixture usage
  • Parametrized tests
  • Property-based tests (Hypothesis)
  • Integration tests

3. Hypothesis Patterns

  • Idempotent operations
  • Commutative properties
  • Type stability
  • Length preservation
  • Never-crash properties

4. Documentation

  • Explain when to use each pattern
  • Add "why" comments throughout
  • Link to pytest/Hypothesis docs
  • Update .claude/rules.md to reference template

Example Patterns

# Traditional
def test_specific_case():
    assert function(input) == output

# Property-based
@given(st.integers())
def test_idempotent(x):
    assert f(f(x)) == f(x)

# Parametrized
@pytest.mark.parametrize("input,expected", [
    (1, 1), (2, 4), (3, 9)
])
def test_cases(input, expected):
    assert function(input) == expected

Pattern Coverage Matrix

Pattern Use Case Example
Unit test Known input/output login with valid credentials
Property test Mathematical properties reversing twice = original
Parametrized Multiple similar cases boundary values
Fixture Shared setup database connection
Integration End-to-end workflow complete user journey

Success Criteria

  • Template covers all common test patterns
  • AI agents can reference it successfully
  • Reduces test quality issues
  • Serves as team reference

Dependencies

Estimated Effort: 2-3 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requesttesting

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions