TDD & CI/CD
This article is a definition of terms for TDD and CI/CD – including exam questions, core components, and tags.
In a Nutshell
TDD: Tests are written before code (Red–Green–Refactor). CI/CD: automated integration and delivery via pipelines.
Compact Technical Description
TDD follows the cycle:
- Red: write a test that fails
- Green: minimal code to make the test pass
- Refactor: improve without changing functionality
CI/CD:
- CI: build + tests after every commit
- CD: automated delivery (Delivery to staging, Deployment to production)
Exam-Relevant Key Points
- TDD = test first
- Red-Green-Refactor
- CI = automated building/testing
- CD = automated delivery (IHK-relevant)
- TDD increases test coverage
- CI/CD reduces manual errors (security)
- Faster releases (cost-effectiveness)
- Pipeline must be documented
Core Components
- Unit Tests
- Test frameworks (JUnit/pytest)
- CI servers (Jenkins/GitHub Actions)
- Build Tools
- Container/Deployment
- Pipeline scripts
- Rollback strategies
- Staging environments
- Code quality tools
Practical Example (pytest)
def add(a, b):
return a + b
def test_add():
assert add(2, 3) == 5
Advantages and Disadvantages
Advantages
- Higher code quality
- Automated QA
- Faster error detection
- Repeatable deployments
Disadvantages
- Initial overhead
- Infrastructure required
- Discipline required
Typical Exam Questions (with Short Answer)
- What does Red-Green-Refactor mean? Write a test, implement minimally, then refactor.
- Goal of CI? Automated testing and integration.
- Delivery vs Deployment? Delivery to staging, Deployment to production.
Free Response
TDD forces early thinking about requirements and interfaces. CI/CD is standard in the DevOps context and demonstrates professionalism in projects.
Learning Strategy
- Develop a small function using TDD.
- Set up a GitHub Actions pipeline for build/test.
- Sketch the pipeline on paper (for exams).
- No deployment without tests.