Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Test Suite for dev-environment

Comprehensive automated test suite for the dev-environment project.

📁 Directory Structure

tests/
├── README.md                    # This file
├── test_runner.sh               # Main test runner
├── unit/                        # Unit tests
│   ├── test_functions.sh        # Helper function tests
│   ├── test_syntax.sh           # Syntax validation tests
│   └── test_package_parsing.sh  # Package config parsing tests
├── integration/                 # Integration tests
│   ├── test_update.sh           # Update script tests
│   ├── test_verification.sh     # Verification script tests
│   └── test_git_hook.sh         # Git hook tests
└── fixtures/                    # Test data
    ├── test_packages.conf       # Sample package config
    └── test_configs/            # Sample config files
        └── test_zshrc           # Sample zshrc

🚀 Running Tests

Run All Tests

./tests/test_runner.sh

Run Unit Tests Only

./tests/test_runner.sh --unit

Run Integration Tests Only

./tests/test_runner.sh --integration

Verbose Output

./tests/test_runner.sh --verbose

Via Makefile

make test           # Syntax validation
cd tests && ./test_runner.sh  # Full test suite

📊 Test Coverage

Unit Tests (3 files, ~35 tests)

  1. test_functions.sh

    • Helper function tests
    • String operations
    • File path resolution
    • Critical script existence
    • Directory structure validation
  2. test_syntax.sh

    • Syntax validation for all scripts
    • Shebang validation
    • Executable permissions
    • Script integrity
  3. test_package_parsing.sh

    • Package configuration parsing
    • Array existence and validity
    • Package list verification
    • Duplicate detection

Integration Tests (3 files, ~25 tests)

  1. test_update.sh

    • Update script functionality
    • Flag support (--dry-run, --auto, --help)
    • Error handling
    • Git repository checks
  2. test_verification.sh

    • Verification script functionality
    • Flag support (--fix, --deep, --report)
    • Issue tracking
    • Error handling
  3. test_git_hook.sh

    • Git hook template validation
    • Change detection (packages, scripts)
    • Hook installation in install.sh/setup.sh
    • Syntax and error handling

Total: ~60 tests

✅ Assertion Functions

The test runner provides these assertion functions:

  • assert_equals expected actual test_name
  • assert_not_equals not_expected actual test_name
  • assert_true condition test_name
  • assert_file_exists file test_name
  • assert_command_exists command test_name

📝 Writing New Tests

Unit Test Template

#!/bin/bash

# Get paths
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

echo "Running my new tests..."
echo ""

# Test 1: Example test
test_example() {
    assert_equals "expected" "actual" "Test description"
}

# Run all tests
test_example

echo ""
echo "My new tests complete"

Integration Test Template

#!/bin/bash

# Get paths
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

echo "Running integration tests..."
echo ""

# Test 1: Script exists
test_script_exists() {
    assert_file_exists "$REPO_ROOT/script.sh" "script.sh exists"
}

# Run all tests
test_script_exists

echo ""
echo "Integration tests complete"

🎯 Test Guidelines

  1. Naming: Test files must start with test_ and end with .sh
  2. Executable: All test files must be executable (chmod +x)
  3. Isolated: Tests should not depend on each other
  4. Fast: Keep tests quick (< 1 second each when possible)
  5. Clear: Use descriptive test names
  6. Self-contained: Tests should clean up after themselves

🔄 CI/CD Integration

Tests run automatically on:

  • Every push to the repository
  • Every pull request
  • Manual workflow dispatch

See .github/workflows/test.yml for CI/CD configuration.

📈 Coverage Goals

  • Target: 80%+ test coverage
  • Current: ~60 tests covering core functionality
  • Status: Good coverage of critical paths

🐛 Debugging Failed Tests

Verbose Mode

./tests/test_runner.sh --verbose

Run Single Test

bash tests/unit/test_functions.sh

Check Syntax

bash -n tests/unit/test_functions.sh

📚 Resources

✅ Success Criteria

Tests are considered successful when:

  • ✅ All tests pass
  • ✅ Pass rate is 100%
  • ✅ No syntax errors
  • ✅ Exit code is 0

Last Updated: 2025-11-04 Test Suite Version: 1.0 Status: Active