Skip to content
IRC-CodingIRC-Coding
TDDTest-Driven DevelopmentCI/CDContinuous IntegrationContinuous DeploymentRed Green RefactorAutomation

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

Master Test-Driven Development with Red-Green-Refactor cycles and automated CI/CD pipelines using GitHub Actions and Jenkins.

S

schutzgeist

2 min read
TDD & CI/CD Explained: Red-Green-Refactor

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

  1. Unit Tests
  2. Test Frameworks (e.g., JUnit, pytest)
  3. CI Servers (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

# 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)

  1. What is “Red-Green-Refactor” in TDD? Write a failing test (Red), implement minimal code to pass it (Green), then refactor.
  2. What is the goal of CI? Automatically test and merge code changes.
  3. How does CD support the development process? By automatically deploying tested versions.
  4. Which tests run automatically in CI/CD? Unit, integration, and optionally acceptance tests.
  5. What is the difference between Continuous Delivery and Deployment? Delivery stops at staging; Deployment goes directly to production.
  6. How does TDD improve software quality? Bugs are caught early and code is better structured.
  7. Which CI/CD tools are commonly used? Jenkins, GitHub Actions, GitLab CI, Travis CI.
  8. How do you document a CI/CD process? As a pipeline configuration (YAML file) with descriptions of all steps.

Key Resources

  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:

Nächster Artikel in Software Architecture

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

Related Posts