TDD & CI/CD – Red-Green-Refactor & Automated Pipelines
This article is a glossary entry covering TDD and CI/CD, including exam questions and tags.
In a Nutshell
Test-Driven Development (TDD) is a development approach where you write tests before writing code. CI/CD describes automated processes for continuously integrating and delivering software.
Technical Overview
Test-Driven Development (TDD) follows the cycle: Red – Green – Refactor. You start by writing a failing test (Red), then write the minimal code to make it pass (Green), and finally optimize the implementation (Refactor). TDD promotes clean, testable code and catches errors early. CI/CD stands for Continuous Integration—automatically merging code into the main branch with tests—and Continuous Deployment/Delivery, which automatically releases changes to staging or production environments. CI/CD relies on tools like GitHub Actions, Jenkins, or GitLab CI, combined with unit, integration, and acceptance tests.
Key Exam Points
- TDD = write tests first, implement second
- Red-Green-Refactor cycle
- CI = automated building and testing after each commit
- CD = automated deployment to target environments (IHK-relevant)
- TDD increases test coverage and improves code structure
- CI/CD reduces manual errors and security risks
- Faster releases through automation
- Build and deployment processes must be documented
Core Components
- Unit Tests
- Test Frameworks (e.g., JUnit, pytest)
- CI Servers (e.g., Jenkins, GitHub Actions)
- Build Tools (e.g., Maven, Gradle)
- Docker for Deployment
- Pipeline Scripts
- Automated Deployment (CD)
- Rollback Strategies
- Staging Environments
- Test Coverage and Code Quality Tools
Practical Example
# TDD Example (Python with pytest)
def add(a, b):
return a + b
def test_add():
assert add(2, 3) == 5
The workflow: first write a test that fails (Red). Next, implement add() to make it pass (Green). Finally, refactor the structure if needed (Refactor).
Advantages and Disadvantages
Advantages
- Higher code quality
- Automated quality assurance
- Faster debugging
- Repeatable and secure deployments
Disadvantages
- Higher initial effort
- Infrastructure required (CI/CD systems)
- Demands disciplined practices
Common Exam Questions (with Answers)
- What is “Red-Green-Refactor” in TDD? Write a failing test (Red), implement minimal code to pass it (Green), then refactor.
- What is the goal of CI? Automatically test and merge code changes.
- How does CD support the development process? By automatically deploying tested versions.
- Which tests run automatically in CI/CD? Unit, integration, and optionally acceptance tests.
- What is the difference between Continuous Delivery and Deployment? Delivery stops at staging; Deployment goes directly to production.
- How does TDD improve software quality? Bugs are caught early and code is better structured.
- Which CI/CD tools are commonly used? Jenkins, GitHub Actions, GitLab CI, Travis CI.
- How do you document a CI/CD process? As a pipeline configuration (YAML file) with descriptions of all steps.
Key Resources
- https://martinfowler.com/bliki/TestDrivenDevelopment.html
- https://docs.github.com/en/actions
- https://www.atlassian.com/continuous-delivery
- https://docs.pytest.org/en/latest/
- https://learn.microsoft.com/en-us/azure/devops/pipelines/index



