BDD(Behavior-Driven Development, 행위 주도 개발)는 비즈니스 이해관계자, 개발자, QA가 공통 언어(Gherkin)로 소프트웨어 동작을 명세하고 검증하는 개발 방법론이다. Cucumber가 대표적인 도구다.
TDD vs BDD
| 항목 | TDD | BDD |
|---|
| 초점 | 구현 단위 | 비즈니스 행위 |
| 언어 | 기술적 | 자연어 (Given/When/Then) |
| 대상 | 개발자 | 개발자+QA+기획 |
| 문서화 | 코드 기반 | 명세 문서 겸용 |
Gherkin 문법
gherkin
Feature: 사용자 로그인
Background:
Given 사용자 "Alice" 가 가입되어 있음
Scenario: 정상 로그인
Given 로그인 페이지에 있음
When 이메일 "alice@example.com" 과 비밀번호 "pass123" 입력
And "로그인" 버튼 클릭
Then 대시보드 페이지로 이동
And "Alice님 환영합니다" 메시지 표시
Scenario Outline: 잘못된 비밀번호
When 이메일 "<email>" 과 비밀번호 "<pw>" 입력
Then 오류 메시지 "<msg>" 표시
Examples:
| email | pw | msg |
| alice@example.com | wrong | 비밀번호 오류 |
| unknown@example.com | pass123 | 사용자 없음 |
typescript
// steps/login.steps.ts
import { Given, When, Then } from '@cucumber/cucumber';
import { expect } from '@playwright/test';
Given('로그인 페이지에 있음', async function() {
await this.page.goto('/login');
});
When('이메일 {string} 과 비밀번호 {string} 입력', async function(email: string, pw: string) {
await this.page.fill('#email', email);
await this.page.fill('#password', pw);
});
When('"로그인" 버튼 클릭', async function() {
await this.page.click('button[type=submit]');
});
Then('대시보드 페이지로 이동', async function() {
await expect(this.page).toHaveURL('/dashboard');
});
Then('{string} 메시지 표시', async function(msg: string) {
await expect(this.page.locator('.message')).toContainText(msg);
});
Living Documentation
BDD의 부산물: 항상 최신 상태인 실행 가능한 명세 문서
도구:
- Cucumber Reports: 실행 결과 HTML 리포트
- Serenity BDD: 상세 내러티브 보고서
- Allure: 다양한 차트/통계
이점:
- 기획-개발-QA 간 오해 감소
- 비즈니스 규칙 코드에서 추적 가능
관련 문서