TDD & CI/CD – Red-Green-Refactor & Automated Pipelines
This article is a definition of terms for TDD and CI/CD – including exam questions and tags.
In a Nutshell
Test-Driven Development (TDD) is a development approach in which tests are written before the code. CI/CD describes automated processes for continuously integrating and delivering software.
Compact Technical Description
Test-Driven Development (TDD) follows the cycle: Red – Green – Refactor. First, a failing test is written (Red), then the minimal code to pass it (Green), then optimization occurs (Refactor). TDD promotes clean, testable code and reduces errors early on. CI/CD stands for Continuous Integration (automated merging of code into the main branch with tests) and Continuous Deployment/Delivery, which automatically delivers changes to staging or production. CI/CD uses tools like GitHub Actions, Jenkins, or GitLab CI, combined with unit, integration, and acceptance tests.
Exam-Relevant Key Points
- TDD = Test first, then implementation
- Red-Green-Refactor cycle
- CI = Automated building, testing after each commit
- CD = Automated delivery to target environments (IHK-relevant)
- TDD increases test coverage and structures code
- 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 Server (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
# Example TDD (Python with pytest)
def add(a, b):
return a + b
def test_add():
assert add(2, 3) == 5
Explanation: First the test is written, which fails (Red). Then add() is implemented (Green). Subsequently the structure is improved if necessary (Refactor).
Advantages and Disadvantages
Advantages
- Higher code quality
- Automated quality assurance
- Faster error detection
- Repeatable and secure deployments
Disadvantages
- Higher initial effort
- Infrastructure required (CI/CD systems)
- Requires disciplined approach
Typical Exam Questions (with Short Answers)
- “Red-Green-Refactor” in TDD? Write test (Red), minimal code (Green), then refactoring.
- Goal of CI? Automated testing and merging of code changes.
- CD supports development process? Through automated delivery of tested versions.
- Tests automatic in CI/CD? Unit, integration, and possibly acceptance tests.
- Continuous Delivery vs. Deployment? Delivery = up to staging, Deployment = directly to production.
- TDD promotes software quality? Errors are detected early, code is better structured.
- Frequently used CI/CD tools? Jenkins, GitHub Actions, GitLab CI, Travis CI.
- Document CI/CD process? As pipeline configuration (YAML file) with description of all steps.
Most Important Sources
- 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