Skip to content
IRC-Coding IRC-Coding
TDD Test-Driven Development CI/CD Continuous Integration Continuous Deployment Red Green Refactor Automation

TDD & CI/CD Explained: Red-Green-Refactor

Master Test-Driven Development with Red-Green-Refactor cycles and CI/CD pipelines. Automated builds, tests, deployments using GitHub Actions and Jenkins.

S

schutzgeist

2 min read

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

  1. Unit Tests
  2. Test Frameworks (e.g. JUnit, pytest)
  3. CI Server (e.g. Jenkins, GitHub Actions)
  4. Build Tools (e.g. Maven, Gradle)
  5. Docker for Deployment
  6. Pipeline Scripts
  7. Automated Deployment (CD)
  8. Rollback Strategies
  9. Staging Environments
  10. 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)

  1. “Red-Green-Refactor” in TDD? Write test (Red), minimal code (Green), then refactoring.
  2. Goal of CI? Automated testing and merging of code changes.
  3. CD supports development process? Through automated delivery of tested versions.
  4. Tests automatic in CI/CD? Unit, integration, and possibly acceptance tests.
  5. Continuous Delivery vs. Deployment? Delivery = up to staging, Deployment = directly to production.
  6. TDD promotes software quality? Errors are detected early, code is better structured.
  7. Frequently used CI/CD tools? Jenkins, GitHub Actions, GitLab CI, Travis CI.
  8. Document CI/CD process? As pipeline configuration (YAML file) with description of all steps.

Most Important Sources

  1. https://martinfowler.com/bliki/TestDrivenDevelopment.html
  2. https://docs.github.com/en/actions
  3. https://www.atlassian.com/continuous-delivery
  4. https://docs.pytest.org/en/latest/
  5. https://learn.microsoft.com/en-us/azure/devops/pipelines/index
Back to Blog
Share:

Related Posts