Skip to content

devdojo-it/ai-tdd-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AI TDD Workshop

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.

Prerequisites

  • Node.js (v18.14.0 or higher recommended)
  • npm (comes with Node.js)

Installation

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

Project Structure

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

Available Examples

1. Greeting Kata (Jest TDD)

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

2. String Calculator Kata (Jest TDD)

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

3. Roman Numbers Kata (Jest TDD)

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

4. Library Kata (BDD with Cucumber)

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

Running All Tests

From Root Directory

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

Individual Workspace Commands

Each workspace has its own package.json with specific scripts:

  • Jest workspaces (01, 02, 03): npm test
  • Cucumber workspace (04): npm run bdd

Development Workflow

For TDD Katas (01-03)

  1. Write a failing test
  2. Run the test to see it fail
  3. Write minimal code to make the test pass
  4. Refactor if needed
  5. Repeat

For BDD Kata (04)

  1. Write a feature file in Gherkin syntax
  2. Generate step definitions
  3. Implement the step definitions
  4. Run the BDD tests
  5. Refactor and improve

TypeScript Configuration

Each workspace has its own tsconfig.json configured for:

  • ES2020 target
  • CommonJS modules
  • Strict type checking
  • Node.js module resolution

Dependencies

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

Troubleshooting

Common Issues

  1. Module not found errors: Make sure you've run npm install from the root directory
  2. TypeScript compilation errors: Check that your code follows the strict TypeScript configuration
  3. Cucumber step definition errors: Ensure step definitions match the Gherkin syntax exactly

Getting Help

  • 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

Learning Objectives

  • 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

Next Steps

  1. Start with the Greeting Kata to understand basic TDD
  2. Progress through the String Calculator for edge case handling
  3. Tackle the Roman Numbers Kata for complex logic
  4. Finish with the Library Kata to learn BDD concepts

Happy testing! 🧪

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published