It is important for everyone in a product or service team to understand how practicing behaviour-driven development will grow your output 10x
Disclaimer: no fancy graphs ๐
Since BDD is a subset of test-driven development, let's start there.
[BEHAVIOUR-DRIVEN DEVELOPMENT]
TDD is the practice of writing test code before the implementation code for a new feature or functionality.
[BEHAVIOUR-DRIVEN DEVELOPMENT]
It is a set of best practices for performing TDD within a team.
It carries the same principles and desired outcomes but the primary differentiation comes from focusing on behaviours rather than implementation when writing test cases.
[BEHAVIOUR-DRIVEN DEVELOPMENT]
Let's consider the following new feature request from our product owner:
Description: As a user, I want to be able to input two numbers in a calculator to see their sum. Scenario 1: I type 10 and 2 into the calculator input fields. I press the `add` button. I see the result of 12 appear on the screen.
[BEHAVIOUR-DRIVEN DEVELOPMENT]
suite('calculator', function() {
test('add', function() {
Calculator calculator = new Calculator();
assert.equal(12, calculator.add(10, 2));
});
});describe('when using the calculator', function() {
describe('and adding two numbers', function() {
it('should give the user the sum of the two numbers', function() {
Calculator calculator = new Calculator();
int expectedSum = calculator.add(10, 2);
assert.equal(12, expectedSum);
});
});
});public class Calculator {
...
public int add(int a, int b) {
return a + b;
}
}[BEHAVIOUR-DRIVEN DEVELOPMENT]
It is not complex, wasteful or backwards.
In fact, it is the complete opposite.
๐ Push changes that you know will not break anything in your code base
๐ค Push changes that won't break API contracts with paying partners
๐ Reduce possibility for bugs: eliminate wasted time, maintain uninterrupted daily delivery cadence
[BEHAVIOUR-DRIVEN DEVELOPMENT]
๐ Heightened understanding of the task at hand is paramount to reducing ambiguity, therefor reducing waste
๐ฎ Significantly replace need for technical documentation since the tests explain the codebase from a human perspective
๐จโ๐ฉโ๐งโ๐ฆ Increase engineers commercial understanding of and empathy for the task at hand, improving implementation code quality
[BEHAVIOUR-DRIVEN DEVELOPMENT]
๐ซ Shared knowledge !== shared understanding; Onboard new team members far quicker
โ DevOps, full-stack and support all become far easier to reason with due to the natural language most of your codebase is written in
[BEHAVIOUR-DRIVEN DEVELOPMENT]
BDD by itself is great, but it gets even better with other related practices.
[BEHAVIOUR-DRIVEN DEVELOPMENT]
๐ฐ Good for business; increased reliability, satisfaction & speed to market
โฑ Corrects perception of scope vs time. Time spent writing tests now to get that high test coverage will save you time, therefore money, fixing issues in the long run, fact
[BEHAVIOUR-DRIVEN DEVELOPMENT]
โณ Unit tests (easy, solid, do it)
โ 100% customer journey's via e2e (cumbersome, brittle, vital)
โง 100% integration tests with third parties, decoupled system components etc. (hard, fiddly, integral)
[BEHAVIOUR-DRIVEN DEVELOPMENT]
Nothing is of value until a customer is using it, so getting things in front of customers faster in order to start learning is the smartest thing we can do.
BDD adds extra robustness to a CI/CD pipeline.
ย
The combination of solid tests and coverage along with automated testing gives you plenty of confidence on getting new features into production as quick as possible.
[BEHAVIOUR-DRIVEN DEVELOPMENT]
๐งฌ UI/UX designers need to create simplistic design shifts for individual stories that minimalise potential engineering faults
๐คนโโ๏ธ Product owners need to write stories that contain scenarios which allow engineers to move fast
๐ Data engineers, scientists or analysts need to provide solid measurable outcomes for success for user stories.
๐ Scrum masters need to ensure highly regular planning meetings occur and that engineers vote & discuss as a team and concrete outcomes.
[BEHAVIOUR-DRIVEN DEVELOPMENT]
Simple rule to follow:
1. red:
write the test cases first
tests will fail โ
2. green:
implement the code
tests will pass โ
3. refactor:
improve/refine the code
tests should still pass โ
[BEHAVIOUR-DRIVEN DEVELOPMENT]