Given-When-Then은 TestByExample을 사용하여 시스템 동작을 지정하는 테스트를 표현하는 스타일
BDD(Behavior-Driven Development)의 일환으로 Dan North에 의해 개발
- Given : 테스트 전의 상태
- When : 테스트 행위
- Then : 테스트 검증
일반적인 쓰기방법
Feature: User trades stocks(사용자 주식거래)
Scenario: User requests a sell before close of trading
Given I have 100 shares of MSFT stock
And I have 150 shares of APPL stock
And the time is before close of trading
(사용자가 거래를 마감하기 전에 판매를 요청
MSFT 주식 100주를 가지고 있는 걸 감안
그리고 APPL 주식 150주를 보유
그리고 그 시간은 거래가 끝나기 전)When I ask to sell 20 shares of MSFT stock
(MSFT 주식 20주를 판매) Then I should have 80 shares of MSFT stock
And I should have 150 shares of APPL stock
And a sell order for 20 shares of MSFT stock should have been executed
(그럼 MSFT 주식 80주를 가져야겠다.
그리고 APPL 주식 150주를 가져야 한다.
그리고 MSFT 주식 20주에 대한 매도 주문이 실행되었어야 했다.)
- Given-When-When-Tests 스타일을 사용가능
- Given-When-then-then-then-then을 단위 시험의 비공식 블록을 표시가능
- 복수의 표현을 결합하는 데 사용되는 “ands”를 보는 것이 보통 이 접근법이다.