bdd
TRANSCRIPT
BDDBEHAVIOUR DRIVEN DEVELOPMENT
NO INTEGRATION TESTTWO UNIT TESTS PASSED
WOULDN’T IT BE GREAT?
• Clear requirements
• Measurable acceptance criteria
• Documentation of existing functionality
• Confidence everything works?
“WHAT’S THE PURPOSE OF MEANING?”
WHAT IS BDD
A. A way to structure unit tests
B. Unit tests with a new name
C. Executable specifications
D. Automated Test Scenarios
FORMB.D.D.
Given [initial state]
When [do stuff]
Then [result]
B.D.D.
EXAMPLE
Feature: Green Bottles
Scenario: Should fall from the wall
Given 100 green bottles are standing on the wall
When 1 green bottle accidentally falls
Then there are 99 green bottles standing on the wall
“MAKE IT RUN”THE CODE
module.exports = English.library()
.given("$NUM green bottles are standing on the wall", function(number, next) {
wall = new Wall(number);
next();
})
.when("$NUM green bottle accidentally falls", function(number, next) {
wall.fall(number);
next();
})
.then("there are $NUM green bottles standing on the wall", function(number, next) {
assert.equal(number, wall.bottles);
next();
});
EXECUTE IT!
macbookpro:yadda-tutorial machiel$ mocha --reporter spec test.js
100 Green Bottles Should fall from the wall ✓ Given 100 green bottles are standing on the wall ✓ When 1 green bottle accidentally falls ✓ Then there are 99 green bottles standing on the wall
3 passing (34ms)
DONEC QUIS NUNC
ALTERNATIVE: CODE DECORATION
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
A suitecontains spec with an expectation
DIVIDE ET IMPERA
ONE SCENARIO TO RULE THEM ONE
SCENARIO
SERVER SIDE TEST
UI TEST
MULTI BROWSER
TEST
PERFORMANCE TEST
“COMPARISON IS THE THIEF OF JOY”BDD VS TDD
• Unit
• One function or class
• language of the system
• fine grained
• Behaviour
• the whole system
• language of the user
• coarse
BENEFITS
USER LEVEL TESTS
• Test linked to Story
• Done or not
• Technology agnostic
• Multiple usages
• Refactor friendly
CLARITY SECURITYSPEED
BDD IN A NUTSHELL
LIBRARIES
Pure BDD in JS https://github.com/acuminous/yadda
Yadda in crossbrowser testing https://github.com/kjelloe/Yadda-WebdriverJS