# 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
```- Clone the repo:
git clone https://github.com/your-username/tdd-webdev.git
- Install dependencies:
npm install
-
Create a test file in the
testsfolder (e.g.,tests/sum.test.js). -
Write a failing test:
const sum = require('../src/sum'); test('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3); });
-
Write the code to pass the test in
src/sum.js:function sum(a, b) { return a + b; } module.exports = sum;
-
Run your test:
npm testYour test should pass!
- Write a failing test: Start with the requirements.
- Make the test pass: Write the simplest code possible.
- Refactor: Clean and optimize your code.
This course covers:
- Writing tests for functions and components.
- TDD for backend APIs.
- TDD for frontend interactions.
Let’s build reliable, test-driven applications together!