Skip to content

TEST RELIABILITY QUICKSTART

GitHub Actions edited this page Feb 4, 2026 · 1 revision

Test Reliability Quick Start

Get started with bulletproof testing in 5 minutes

What You Get

  • 100% reliable tests (zero flakiness)
  • Fast execution (<5 seconds per test)
  • No external dependencies (mocks for Docker, network, etc.)
  • Automatic cleanup (no leftover resources)
  • Cross-platform (macOS, Linux, WSL)

Quick Example

#!/usr/bin/env bash
# my-test.sh - Example reliable test

# Source the framework
source src/tests/lib/reliable-test-framework.sh
source src/tests/mocks/docker-mock.sh

# Your test function
test_my_feature() {
  # Create isolated test directory (auto-cleanup)
  local test_dir=$(create_isolated_test_dir)
  cd "$test_dir"

  # Run commands with mocks (instant, no Docker needed)
  docker run --name test-app nginx

  # Verify
  if docker ps | grep -q "test-app"; then
    echo "✓ Test passed"
    return 0
  else
    echo "✗ Test failed"
    return 1
  fi
}

# Run with timeout protection
run_test_with_timeout test_my_feature 30

Run it:

bash my-test.sh
# ✓ Test passed (completes in <1 second)

Install Pre-Commit Hook

bash scripts/install-pre-commit-hook.sh

Now every commit runs fast checks automatically.

See It In Action

# Run the complete example showing all features
bash src/tests/examples/reliable-test-example.sh

Output:

╔════════════════════════════════════════════════════════════╗
║         Reliable Test Framework Examples                  ║
╚════════════════════════════════════════════════════════════╝

→ Test 1: Basic test with timeout and cleanup
  ✓ Test file created successfully
  ✓ Test completed within timeout

→ Test 2: Guaranteed cleanup (even on failure)
  Setup: Created resource at /tmp/tmp.XXXXXXXXXX
  ✓ Resource created in setup directory
  Cleanup: Removed resource
  ✓ Test passed and cleanup executed

→ Test 3: Using Docker mock (fast, no Docker required)
  ✓ Container created (mocked)
  ✓ Container lifecycle tested without real Docker

→ Test 4: Using network mock (no real HTTP requests)
  ✓ API request mocked successfully
  ✓ Error response handled correctly

→ Test 5: Using time mock (instant timeouts)
  ✓ Time advanced 60 seconds instantly
  ✓ Time multiplier works (10x speed)

... (10 tests total)

═══════════════════════════════════════════════════════════
Test Summary:
  Total:  24
  Passed: 24
  Failed: 0
═══════════════════════════════════════════════════════════
✓ All examples passed!

Common Patterns

Pattern 1: Test with Auto-Cleanup

source src/tests/lib/reliable-test-framework.sh

test_creates_files() {
  # Auto-cleanup test directory
  local test_dir=$(create_isolated_test_dir)
  cd "$test_dir"

  # Create files
  echo "test" > file.txt

  # Verify
  [[ -f "file.txt" ]] && echo "✓ File created"

  # Cleanup happens automatically
}

run_test_with_timeout test_creates_files 10

Pattern 2: Test with Docker Mock

source src/tests/mocks/docker-mock.sh

test_docker_operations() {
  # No Docker required!
  docker run --name test nginx
  docker ps
  docker stop test
  docker rm test

  echo "✓ Docker operations tested (mocked)"
}

run_test_with_timeout test_docker_operations 10

Pattern 3: Test with Network Mock

source src/tests/mocks/network-mock.sh

test_api_call() {
  # Setup mock response
  register_mock_response \
    "https://api.example.com/status" \
    200 \
    '{"status": "ok"}'

  # Make request (instant, no network)
  response=$(curl -s https://api.example.com/status)

  echo "$response" | grep -q "ok" && echo "✓ API call tested"
}

run_test_with_timeout test_api_call 10

Pattern 4: Test with Retry Logic

source src/tests/lib/reliable-test-framework.sh

test_flaky_operation() {
  ATTEMPT=0

  flaky_func() {
    ATTEMPT=$((ATTEMPT + 1))
    [[ $ATTEMPT -ge 3 ]] && return 0 || return 1
  }

  # Retry up to 5 times
  retry_on_failure flaky_func 5 && echo "✓ Flaky operation handled"
}

run_test_with_timeout test_flaky_operation 10

Tools

Find Flaky Tests

bash scripts/find-flaky-tests.sh --iterations 10
# Runs each test 10 times and reports flakiness

Analyze Performance

bash scripts/test-performance-analysis.sh
# Shows slow tests and suggests optimizations

Next Steps

  1. Read the full guide: docs/development/TEST-RELIABILITY-GUIDE.md
  2. See implementation details: docs/development/TEST-RELIABILITY-IMPLEMENTATION.md
  3. Run examples: bash src/tests/examples/reliable-test-example.sh
  4. Install pre-commit hook: bash scripts/install-pre-commit-hook.sh
  5. Migrate your tests to use the framework

Key Benefits

Before After
Tests flaky (50-90% pass rate) 100% pass rate
Slow (30+ seconds per test) Fast (<5 seconds)
Docker required Mocked (instant)
Network required Mocked (offline works)
Cleanup manual Automatic
Hard to debug Clear error messages

Quick Reference

# Framework
source src/tests/lib/reliable-test-framework.sh

# Timeout
run_test_with_timeout my_test 30

# Cleanup
with_cleanup test_func cleanup_func

# Isolation
test_dir=$(create_isolated_test_dir)
port=$(get_random_port)

# Retry
retry_on_failure flaky_test 3

# Wait
wait_for_condition is_ready 30

# Mocks
source src/tests/mocks/docker-mock.sh      # Docker
source src/tests/mocks/network-mock.sh     # HTTP
source src/tests/mocks/time-mock.sh        # Time
source src/tests/mocks/filesystem-mock.sh  # Files

Summary

You now have a production-ready test infrastructure that ensures:

  • Zero flakiness
  • Fast execution
  • Complete isolation
  • Cross-platform compatibility
  • Easy debugging

Start writing bulletproof tests today!

Home


Getting Started


Commands


Features


Configuration


Plugins (87 + 10 monitoring)

Free (25)
Pro (62)
Planned (26)
  • plugin-audit
  • plugin-blog
  • plugin-checkout
  • plugin-commerce
  • plugin-drm
  • plugin-export
  • plugin-flow
  • plugin-import
  • plugin-ldap
  • plugin-mailgun
  • plugin-media
  • plugin-oauth-providers
  • plugin-pages
  • plugin-postmark
  • plugin-rate-limit
  • plugin-reports
  • plugin-saml
  • plugin-scheduler
  • plugin-sendgrid
  • plugin-sso
  • plugin-subscription
  • plugin-thumb
  • plugin-transcoder
  • plugin-twilio
  • plugin-waf
  • plugin-watermark

Guides


Architecture


Reference


Licensing


Security


Brand


Operations


Contributing


Admin


Changelog


All commands (52)

Clone this wiki locally