A comprehensive collection of Python exercises specifically designed for software testers to develop programming skills, automation capabilities, and testing expertise.
This repository contains 17 carefully crafted exercises organized into three difficulty levels, each focusing on real-world testing scenarios and practical skills that software testers need in their daily work.
Location: 1-basic-exercises/
Focus: Fundamental Python concepts and basic testing scenarios
- String Validation - Input validation, boundary conditions, string operations
- List Operations - Data structure operations, edge cases, searching algorithms
- Simple Calculator - Mathematical operations, exception handling, type validation
- Password Validator - Multiple validation criteria, security testing concepts
- File Reader - File I/O testing, error scenarios, data processing
Location: 2-intermediate-exercises/
Focus: Object-oriented programming, complex data structures, real-world testing applications
- Test Data Generator - Generating realistic test data for various scenarios
- API Response Parser - JSON validation, schema validation, error handling
- Test Case Manager - Managing test cases and execution results
- Configuration Validator - Validating application configurations
- Log File Analyzer - Analyzing application logs for patterns and issues
- Database Mock - Creating mock database operations for testing
Location: 3-advanced-exercises/
Focus: Framework design, advanced patterns, distributed systems
- Test Framework Builder - Building a custom testing framework from scratch
- API Test Automation - Comprehensive API testing automation framework
- Performance Test Suite - Performance testing and load simulation framework
- Test Data Factory - Advanced test data generation and management
- Mock Server Framework - HTTP mock server for API testing
- Test Orchestrator - Distributed test execution and orchestration
- Python 3.8 or higher
- Basic understanding of programming concepts
- Familiarity with testing terminology
- Clone or download this repository
- Navigate to the project directory
- Create and activate a virtual environment:
python -m venv .venv # Windows .venv\\Scripts\\activate # Unix/macOS source .venv/bin/activate
- Install basic dependencies (optional):
pip install pytest requests
Each exercise is self-contained with detailed instructions:
# Navigate to an exercise level
cd 1-basic-exercises
# Run a specific exercise
python 01_string_validation.pyThis repository includes a comprehensive test suite to validate your exercise implementations and track your progress.
# Run all basic level tests
python -m pytest tests/basic/ -v
# Run specific exercise tests
python -m pytest tests/basic/test_01_string_validation.py -v
# Run tests for intermediate exercises
python -m pytest tests/intermediate/ -vThe tests/ directory contains:
- Basic tests:
tests/basic/- Tests for exercises 1-5 - Intermediate tests:
tests/intermediate/- Tests for exercises 6-11 - Advanced tests:
tests/advanced/- Tests for exercises 12-17 - Test utilities: Fixtures, helpers, and configuration files
# Run the interactive test runner
python tests/run_tests.pyThis will present a menu to choose which tests to run.
# Run all tests
python tests/test_runner.py --all
# Run tests by level
python tests/test_runner.py --level basic
python tests/test_runner.py --level intermediate
python tests/test_runner.py --level advanced
# Run specific exercise tests
python tests/test_runner.py --exercise 01_string_validation
# Generate coverage report
python tests/test_runner.py --level basic --coverage
# List available exercises
python tests/test_runner.py --list
# Validate test environment
python tests/test_runner.py --validateEach test file includes:
- Unit tests for individual functions
- Integration tests for complete workflows
- Edge case testing for boundary conditions
- Error handling validation
- Performance tests for larger inputs
Tests are organized into logical groups:
# Run only fast tests
python -m pytest tests/ -m "not slow"
# Run performance tests
python -m pytest tests/ -m "slow"
# Run specific test categories
python -m pytest tests/ -k "test_validation"- β Tests pass: Exercise is correctly implemented
- β Tests fail: Implementation needs work or doesn't exist yet
- βοΈ Tests skipped: Module couldn't be imported (not implemented)
FAILED tests/basic/test_01_string_validation.py - ImportError
SKIPPED - Could not import string validation module
This is expected - tests will fail until you implement the exercises.
FAILED tests/basic/test_01_string_validation.py::test_is_valid_email - AssertionError
Tests help guide your implementation by showing what functionality is expected.
PASSED tests/basic/test_01_string_validation.py::test_is_valid_email
Green tests indicate your implementation meets the requirements.
- Read the exercise description in the exercise file
- Run the tests to see what needs to be implemented:
python -m pytest tests/basic/test_01_string_validation.py -v
- Implement functions until tests pass
- Refactor and improve while keeping tests green
- Add additional features and extend tests as needed
# Install testing dependencies
pip install pytest pytest-cov
# Optional: Install additional testing tools
pip install pytest-html pytest-xdist# Generate HTML coverage report
python tests/test_runner.py --level basic --coverage --html
# Run tests in parallel
python -m pytest tests/ -n auto
# Generate detailed HTML test report
python -m pytest tests/ --html=reports/test_report.html
# Run with specific timeout
python tests/test_runner.py --level basic --timeout 30
# Skip slow tests
python tests/test_runner.py --level basic --markers "not slow"- Start with Basic Exercises (1-5)
- Focus on understanding Python syntax and concepts
- Practice writing simple test scenarios
- Learn error handling and edge case testing
- Complete Basic Exercises first
- Tackle Intermediate Exercises (1-6)
- Focus on object-oriented programming
- Learn to work with APIs, databases, and configurations
- Practice building reusable testing utilities
- Complete Basic and Intermediate exercises
- Dive into Advanced Exercises (1-6)
- Focus on framework design and architecture
- Learn advanced patterns and distributed systems
- Build production-ready testing tools
By completing these exercises, you will:
β Master Python fundamentals relevant to testing β Build practical testing utilities and automation tools β Understand testing frameworks and their architecture β Learn data validation and processing techniques β Practice error handling and edge case testing β Develop API testing and mocking skills β Create performance testing capabilities β Design extensible and maintainable test code
- Python syntax, data structures, and OOP
- Error handling and exception management
- File I/O and data processing
- Regular expressions and pattern matching
- Async programming and concurrency
- Test case design and management
- Data-driven testing approaches
- Mock objects and test doubles
- API testing and validation
- Performance testing fundamentals
- Test automation frameworks
- Design patterns and architecture
- Plugin systems and extensibility
- Configuration management
- Logging and monitoring
- Documentation and code quality
PythonExercise/
βββ README.md # This file
βββ CLAUDE.md # AI assistant guidance
βββ 1-basic-exercises/
β βββ README.md # Basic exercises overview
β βββ 01_string_validation.py # String operations and validation
β βββ 02_list_operations.py # List manipulation and searching
β βββ 03_simple_calculator.py # Math operations with error handling
β βββ 04_password_validator.py # Complex validation rules
β βββ 05_file_reader.py # File operations and processing
βββ 2-intermediate-exercises/
β βββ README.md # Intermediate exercises overview
β βββ 01_test_data_generator.py # Test data generation
β βββ 02_api_response_parser.py # API response validation
β βββ 03_test_case_manager.py # Test case organization
β βββ 04_config_validator.py # Configuration validation
β βββ 05_log_analyzer.py # Log file analysis
β βββ 06_database_mock.py # Database mocking
βββ 3-advanced-exercises/
βββ README.md # Advanced exercises overview
βββ 01_test_framework.py # Custom testing framework
βββ 02_api_automation.py # API testing automation
βββ 03_performance_testing.py # Performance testing suite
βββ 04_test_data_factory.py # Advanced data generation
βββ 05_mock_server.py # HTTP mock server
βββ 06_test_orchestrator.py # Distributed test execution
Each exercise builds upon previous concepts while introducing new challenges and techniques.
All exercises are based on actual testing scenarios you'll encounter in professional software testing.
Each exercise includes:
- Clear problem statements
- Learning objectives
- Implementation guidelines
- Test cases for verification
- Extension suggestions
Each exercise is complete and runnable on its own, with no external dependencies required for core functionality.
- Code Quality: Clean, readable, and well-documented code
- Error Handling: Proper exception handling and edge case management
- Testing: Writing tests for your testing tools
- Documentation: Clear docstrings and comments
- Modularity: Reusable components and separation of concerns
- Performance: Efficient algorithms and resource management
Throughout the exercises, you'll encounter and implement:
- Page Object Model patterns
- Data-Driven Testing approaches
- Mock and Stub implementations
- Factory and Builder patterns
- Observer and Command patterns
- Repository and Strategy patterns
Each exercise includes test cases and examples to verify your implementation.
- Mark exercises as complete in your personal notes
- Build a portfolio of testing utilities
- Integrate tools across different exercises
- Combine exercises to create larger systems
- Add new features and capabilities
- Integrate with popular testing frameworks
- Deploy tools in real testing environments
- Use the Test Data Generator with API Automation
- Combine the Mock Server with the Test Framework
- Integrate Log Analyzer with Performance Testing
- Use Database Mock across multiple test suites
Advanced exercises include production-ready features:
- Configuration management
- Logging and monitoring
- Error reporting and recovery
- Scalability considerations
- Security best practices
- "Effective Python" by Brett Slatkin
- "Clean Code" by Robert C. Martin
- "Test-Driven Development" by Kent Beck
- "Continuous Delivery" by Jez Humble
- pytest - Modern Python testing framework
- unittest - Built-in Python testing framework
- Robot Framework - Keyword-driven testing framework
- behave - Behavior-driven development framework
- requests - HTTP library for Python
- aiohttp - Async HTTP client/server framework
- httpx - Modern HTTP client
- Postman - API development environment
Each exercise includes:
- Detailed problem descriptions
- Implementation hints and tips
- Common pitfalls to avoid
- Extension suggestions
- Reference implementations (in comments)
After completing all exercises, you'll have:
- A comprehensive portfolio of testing tools
- Deep understanding of Python for testing
- Experience with multiple testing patterns
- Ready-to-use utilities for real projects
- Foundation for advanced testing automation
Happy coding and testing! π§ͺβ¨
This collection represents hundreds of hours of carefully crafted exercises designed specifically for software testers. Each exercise teaches practical skills you'll use in your testing career while building a strong foundation in Python programming.
Start with the basics, work your way through intermediate challenges, and tackle the advanced exercises to become a proficient testing automation engineer!