Skip to content

dht/tdd

Repository files navigation

# Test-Driven Development (TDD) for Web Development

Welcome to the **TDD for Web Development** repository! This repo is designed for beginners learning Test-Driven Development (TDD) as part of a web development course.

## What is TDD?

Test-Driven Development is a software development process that emphasizes writing tests **before** writing the actual code. The cycle typically follows these three steps:

1. **Red**: Write a failing test for a new feature or function.
2. **Green**: Write the minimum amount of code necessary to make the test pass.
3. **Refactor**: Clean up the code while ensuring the test still passes.

TDD ensures your code is reliable, maintainable, and meets the requirements from the start.

## Why TDD?

- **Improves Code Quality**: Encourages simple, efficient, and bug-free code.
- **Speeds Up Debugging**: Tests identify issues before they reach production.
- **Ensures Features Work**: You know your code meets requirements because you wrote tests for them.

## Folder Structure

This repository contains the following:

```plaintext
.
├── src/          # Your application code
├── tests/        # Test files
├── README.md     # You are here!
└── package.json  # Project dependencies and scripts
```

Getting Started

Prerequisites

  1. Node.js
  2. A testing framework like Jest or Mocha.

Setup

  1. Clone the repo:
    git clone https://github.com/your-username/tdd-webdev.git
  2. Install dependencies:
    npm install

Writing Your First Test

  1. Create a test file in the tests folder (e.g., tests/sum.test.js).

  2. Write a failing test:

    const sum = require('../src/sum');
    
    test('adds 1 + 2 to equal 3', () => {
      expect(sum(1, 2)).toBe(3);
    });
  3. Write the code to pass the test in src/sum.js:

    function sum(a, b) {
      return a + b;
    }
    
    module.exports = sum;
  4. Run your test:

    npm test

    Your test should pass!

TDD Workflow

  • Write a failing test: Start with the requirements.
  • Make the test pass: Write the simplest code possible.
  • Refactor: Clean and optimize your code.

Example Topics

This course covers:

  • Writing tests for functions and components.
  • TDD for backend APIs.
  • TDD for frontend interactions.

Helpful Resources


Let’s build reliable, test-driven applications together!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published