0
0
Testing Fundamentalstesting~8 mins

Test-driven development (TDD) concept in Testing Fundamentals - Framework Patterns

Choose your learning style9 modes available
Framework Mode - Test-driven development (TDD) concept
Folder Structure of a TDD Project
  /project-root
  ├── src/
  │   └── main_code.py       # Application code
  ├── tests/
  │   ├── test_main_code.py  # Test files written before code
  │   └── __init__.py
  ├── requirements.txt       # Dependencies
  ├── README.md
  └── pytest.ini             # Test runner config
  
Test Framework Layers in TDD
  • Test Layer: Write small, failing tests first that define desired behavior.
  • Code Layer: Write just enough code to pass the tests.
  • Refactor Layer: Clean and improve code without changing behavior.
  • Utilities: Helpers for test setup, mocks, or common assertions.
  • Configuration: Settings for test runner and environment.
Configuration Patterns for TDD

Use simple config files to control test runs:

  • Specify test discovery paths (e.g., tests/ folder).
  • Set environment variables for test mode.
  • Use separate config for different environments (dev, ci).
  • Keep credentials out of tests; use mocks or test doubles.

Example pytest.ini content:

  [pytest]
  testpaths = tests
  addopts = -v --tb=short
  
Test Reporting and CI/CD Integration
  • Use test runner output to see pass/fail results immediately.
  • Generate reports in formats like JUnit XML for CI tools.
  • Integrate tests in CI pipelines to run on every code push.
  • Fail builds if tests fail to ensure quality.
Best Practices for TDD Framework Design
  1. Write tests before writing code to clarify requirements.
  2. Keep tests small and focused on one behavior at a time.
  3. Run tests frequently to get fast feedback.
  4. Refactor code and tests regularly to keep code clean.
  5. Use descriptive test names to explain what is tested.
Self Check Question

Where in this folder structure would you add a new test for a feature you want to develop?

Key Result
Write tests first, then code to pass tests, then refactor for clean design.