This repository contains a collection of Test-Driven Development (TDD) and Behavior-Driven Development (BDD) examples using TypeScript, Jest, and Cucumber. The workshop is organized as a monorepo with multiple kata examples to practice different testing approaches.
- Node.js (v18.14.0 or higher recommended)
- npm (comes with Node.js)
This is a monorepo using npm workspaces. All dependencies are managed at the root level.
# Clone the repository
git clone https://github.com/devdojo-it/ai-tdd-workshop.git
cd ai-tdd-workshop
# Install all dependencies for all workspaces
npm install
ai-tdd-workshop/
├── examples/
│ ├── 01-greeting-kata/ # Basic TDD with Jest
│ ├── 02-string-calculator-kata/ # TDD with edge cases
│ ├── 03-roman-numbers-kata/ # TDD with complex logic
│ └── 04-library-kata-bdd/ # BDD with Cucumber
├── package.json # Root package.json with workspaces
└── README.md
Location: examples/01-greeting-kata/
Testing Framework: Jest
Focus: Basic TDD principles
Run tests:
cd examples/01-greeting-kata
npm test
Or from root:
npm test --workspace=greeting
Location: examples/02-string-calculator-kata/
Testing Framework: Jest
Focus: TDD with edge cases and error handling
Run tests:
cd examples/02-string-calculator-kata
npm test
Or from root:
npm test --workspace=string-calculator
Location: examples/03-roman-numbers-kata/
Testing Framework: Jest
Focus: TDD with complex business logic
Run tests:
cd examples/03-roman-numbers-kata
npm test
Or from root:
npm test --workspace=roman-numbers
Location: examples/04-library-kata-bdd/
Testing Framework: Cucumber (BDD)
Focus: Behavior-Driven Development with Gherkin syntax
Run BDD tests:
cd examples/04-library-kata-bdd
npm run bdd
Or from root:
npm run bdd --workspace=library-kata-bdd
You can run tests for all workspaces at once:
# Run all Jest tests across all workspaces
npm test --workspaces
# Run BDD tests for the library kata
npm run bdd --workspace=library-kata-bdd
Each workspace has its own package.json with specific scripts:
- Jest workspaces (01, 02, 03):
npm test
- Cucumber workspace (04):
npm run bdd
- Write a failing test
- Run the test to see it fail
- Write minimal code to make the test pass
- Refactor if needed
- Repeat
- Write a feature file in Gherkin syntax
- Generate step definitions
- Implement the step definitions
- Run the BDD tests
- Refactor and improve
Each workspace has its own tsconfig.json
configured for:
- ES2020 target
- CommonJS modules
- Strict type checking
- Node.js module resolution
All dependencies are managed at the root level:
- Jest: Testing framework for unit tests
- ts-jest: Jest transformer for TypeScript
- @cucumber/cucumber: BDD testing framework
- ts-node: TypeScript execution for Node.js
- TypeScript: TypeScript compiler
- @types/jest: TypeScript definitions for Jest
- @types/node: TypeScript definitions for Node.js
- Module not found errors: Make sure you've run
npm install
from the root directory - TypeScript compilation errors: Check that your code follows the strict TypeScript configuration
- Cucumber step definition errors: Ensure step definitions match the Gherkin syntax exactly
- Check the individual test files for examples
- Review the Jest documentation for unit testing patterns
- Check the Cucumber documentation for BDD patterns
- Each kata includes example implementations to guide you
- TDD Fundamentals: Red-Green-Refactor cycle
- Jest Testing: Assertions, mocking, and test organization
- BDD Concepts: Given-When-Then syntax and behavior specification
- TypeScript Testing: Type-safe test development
- Monorepo Management: Working with npm workspaces
- Start with the Greeting Kata to understand basic TDD
- Progress through the String Calculator for edge case handling
- Tackle the Roman Numbers Kata for complex logic
- Finish with the Library Kata to learn BDD concepts
Happy testing! 🧪