Skip to content

Test: Expand Coverage (Edge Cases, API, Snapshots) #12

@webreidi

Description

@webreidi

Goal

Strengthen confidence in gameplay logic and API stability by expanding automated tests: domain edge cases, API contract tests, and snapshot verification of guess evaluations.

Motivation

  • Prevent regressions as new features (persistence, validation, variants) land
  • Catch subtle duplicate-letter scoring bugs
  • Lock in API response structure

Scope

Cover domain services (Issue #8), persistence behaviors (Issue #9 integration-lite), and API endpoints shape (ProblemDetails + success payloads).

Additions

  1. Domain Unit Tests
    • Duplicate letters (target: APPLE, guess: PAPAL, etc.)
    • All identical letters (AAAAA scenarios)
    • Win on final allowed attempt boundary
    • Invalid guess length (ensure exception / validation path)
    • Case normalization (input lowercase -> treated correctly)
  2. Guess Evaluation Matrix
    • Table-driven tests enumerating (target, guess, expected pattern) using inline data or MemberData
  3. API Tests (Minimal)
    • Using WebApplicationFactory: start game -> submit guess -> verify DTO shapes
    • ProblemDetails scenarios (duplicate guess, max attempts reached, bad length)
  4. Snapshot Tests
    • Use Verify (Verify.Xunit) or Snapshooter to capture GuessResultDto patterns
    • Store snapshots under Codel-Cloud-Native.Tests/__snapshots__
  5. Persistence (if implemented) Integration-lite
    • Spin up test container for Redis (or in-memory substitute) - optional initial
    • Round-trip session save/load
  6. Test Utilities
    • Builder / factory helpers for GameSession, Guess
    • Random word generator stub for deterministic tests
  7. CI Readiness
    • Category/Trait attributes: [Trait("Category","Integration")] for persistence + API tests
    • Default run excludes Integration unless RunIntegration=true env var

Implementation Plan

  1. Add test helper classes (e.g., TestWordProvider, GameSessionBuilder)
  2. Add evaluation edge case tests
  3. Introduce snapshot library + first snapshot for representative guess result
  4. Add minimal API tests (ensuring use of in-memory persistence fakes if Issue Feature: Add Game Session Persistence & Redis Caching Layer #9 not merged yet)
  5. Add Trait filtering logic in test project (Directory.Build.props or run script) to exclude integration by default
  6. Document how to run full suite in README

Acceptance Criteria

  • Coverage increased for evaluator edge cases (qualitative; ensure new tests present)
  • Snapshot tests pass and fail meaningfully on structure change
  • API tests validate success + error ProblemDetails JSON
  • Integration tests skipped by default unless enabled

Non-Goals

  • Full load / performance testing
  • Browser end-to-end tests

Risks & Mitigation

  • Snapshot churn -> Keep snapshots narrow (only essential fields)

Definition of Done

Merged PR with new tests, snapshots committed, README updated with test running instructions.

Estimated Effort

Small-Medium (3-5h).

Depends on: Issue #8 (domain abstractions), optionally Issue #11 (ProblemDetails shapes).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions