Behavior Driven Development is one of the most commonly misunderstood techniques in DevOps, but it is also one of the key enablers of both an Agile culture and true continuous deployment. This talk will attempt to fill in the missing pieces on exactly what BDD is and how your teams can use it to increase communication, drive quality, and reduce waste. We will also connect the dots on why you need a test-first strategy to enable trunk-based development, continuous integration, and continuous deployment. If your business still struggles with monthly or quarterly big-batch releases, this talk will show you what your teams must do to evolve to the next stage of continuous delivery.
4. 8
The shortest possible line between idea and working
software. Benefits include:
• 44% more time spent on new features
• 50% higher market cap growth over 3 years
• 8000x faster deployment lead time
• 50% less time spent fixing security defects
• 50% lower change-failure rate
• 21% less time spent on unplanned work and
rework
CONTINUOUS DELIVERY
5. 9
• A development practice where developers
integrate code into a shared repository
frequently, preferably several times a day.
• In Continuous Integration, the team should
realize immediately if there are any issues
with the code that prevent it from being
deployed.
• “Continuous Integration doesn’t get rid
of bugs, but it does make them
dramatically easier to find and remove.”
– Martin Fowler
CONTINUOUS INTEGRATION
6. 10
• Ensures that code is always in a ready-to-
deploy state by automatically deploying it
to production.
• Every committed change is expected to be
deployed immediately.
• Deployed is not the same thing as released.
CONTINUOUS DEPLOYMENT
Photo by Harshal S. Hirve on Unsplash
8. 12
Most software systems share the following
characteristics:
• They are shipped with many defects
• The cost of changing them increases over time
• These systems will need to be replaced every 3-5
years.
CURRENT STATE OF DEVELOPMENT
11. 15
TEST-DRIVEN DEVELOPMENT
Test Passes
Refactor
Test Fails
A style of programming in which three activities
are tightly interwoven: coding, testing (in the
form of writing unit tests) and design (in the form
of refactoring).
https://www.agilealliance.org/glossary/tdd
13. 17
Develop Check it works
Develop Check 1 & 2 work
Develop Check 1, 2 & 3 works
Develop Get Bored Stop Checking
Develop, Develop, Develop, Develop, Develop, Develop, Develop, Develop, Develop,
Develop, Develop, Develop, Develop, Develop, Develop, Develop
Test… Hold on… WTH?
Write Unit Tests
UNIT TESTING VS TDD
14. 18
Develop Run Test
Write Test It works
Develop Run Tests
Write Test They work
Develop Run Tests
Write Test They work
Develop Run Tests
Write Test They work
Test?
UNIT TESTING VS TDD
Test Passes
Refactor
Test Fails
15. 19
• Technical debt-free code. Forever.
• Boring deployments.
• Easy refactoring and re-engineering.
• Code assumptions become self-
documenting.
• New developers learn the system
quicker.
WHAT TDD ENABLES
Photo by Ian Stauffer on Unsplash
16. • TDD can’t fix a bad design.
• SOLID design principles still need to be
followed. TDD does not replace
architecture.
• TDD, by itself, does not guarantee
alignment with acceptance criteria.
• Although if you’re doing it right, it should.
• TDD does not mean “Unit Tests”
• It’s perfectly acceptable to include some
integration testing in your TDD effort.
WHAT TDD DOESN’T DO
Photo by Ian Stauffer on Unsplash
17. 21
• You still need lengthy regression-testing cycles before each
release.
• You have frequent production issues with released code.
• Similar issues happen more than once with the same code base.
It is not enough to fix a bug.
You need to guarantee that bug is fixed
forever.
TDD PROBABLY ISN’T BEING DONE IF…
Photo by Ian Stauffer on Unsplash
19. 23
Introduced in 2006 by Dan North and Chris
Matts to fix some problems their clients had
experienced with TDD adoption:
• Not knowing where to start
• Not knowing what to and what not to test
• Not knowing how much to test in one
attempt
• Not knowing what to call their tests
• Not understanding why a test fails
BEHAVIOR-DRIVEN DEVELOPMENT
Photo by Harshal S. Hirve on Unsplash
20. 24
The problem, they decided, was one of
language. So they created a couple of
clarifying rules:
• Test method names should be sentences
that include the word “should”
• They replaced the term “Test” with
“Specification”
• They replaced the term “Test Case” with
“Scenario
• They proposed Given-When-Then to model
appropriate test behavior
BEHAVIOR-DRIVEN DEVELOPMENT
Photo by Geran de Klerk on Unsplash
21. 25
AND A BRIEF RANT ABOUT WHY I HATE PROCESS DIAGRAMS
TDD
Automated Acceptance
Testing
Business BA UX
BA Testers Developers UI
Designers
Vision
Flow
Capabilities
Features
Business Rules
Examples
Shared Understanding
Executable Specifications
Wireframes
Feedback
Visibility
Valuable software
THE BDD PROCESS
22. 26
Behavior-Driven Development rests on two central ideas:
THE CORE OF BDD
Ubiquitous Language so that
everyone in an organization
can focus on the problem
domain
System development driven by
Executable Specifications
24. 28
Behavior-Driven Development rests on two central ideas:
THE CORE OF BDD
Ubiquitous Language so that
everyone in an organization
can focus on the problem
domain
25. 29
Either side will lead to improvements in your process,
but to get the full benefit, you need to do both.
THE CORE OF BDD
26. 30
Here is what BDD adds to standard TDD practice:
THE CORE OF BDD
System development driven by
Executable Specifications
• Given-When-Then pattern for
creating tests
• Testing behaviors rather than
implementations
• Test case as a sentence that
involves the word “should”
• Guaranteed alignment to
Acceptance Criteria
27. 31
Here is what BDD adds to requirements specification:
THE CORE OF BDD
Ubiquitous Language so that
everyone in an organization
can focus on the problem
domain
• Feature Mapping: requirements
discovery
• Example Mapping: creating
testable scenarios
• Three Amigos: Involving
everyone (not just developers)
in test creation
• Combining test creation with
requirements specification
28. 32
Manual Testing
Unit tests: Most of your tests
should live at this level.
Service tests: More expensive to
run and write. No need to
duplicate Unit tests.
E2E and UI tests: use sparingly.
Manual testing: final validation,
and when you cannot automate.
THE AGILE TESTING TRIANGLE
29. 33
BDD DRAWBACKS/CHALLENGES
BECAUSENOTHINGISEVEREASY
Requires a high level of collaboration with the business. Leaders cannot task out
this work and expect a status report later – they must participate in the process.
BDD will not work in a silo – you cannot outsource the tests and expect success.
Test quality matters – if your tests are bad, you will not get the benefits
31. 35
In order to achieve Continuous Delivery
and/or Continuous Deployment, your
software must always be in a releasable
state. This requires the following:
• Creating a repeatable, reliable process for
releasing software
• Automate nearly everything
• Keep everything in version control
• If it hurts, do it more often
• Build quality in!
HOW TO GET TO CONTINUOUS DELIVERY
34. 38
THE DEVOPS SKILL TREE
Think of TDD and BDD like the
Animal Husbandry of DevOps.
It may not seem like much
now, but you’ll need it if you
ever want to explore outer
space.
35. 39
THE DEVOPS SKILL TREE
TDD BDD
Continuous
Integration
Continuous
Deployment
Trunk-Based
Development
Feature Flags
37. 41
FEATURE BRANCHING
Always in releasable state
Always Unit Tested
Trunk
Feature A
Your trunk (the “master” in Git) should be always releasable.
Every branch (including your trunk) should have a well-
understood policy associated with it.
A developer will take a branch for each feature under
development. Following TDD, this branch will be covered by
unit tests, which are also checked in with the source code.
38. 42
FEATURE BRANCHING
Always Unit Tested
Always in releasable state
Always Unit Tested
Trunk
Feature A
Feature B
How do you keep feature branches in synch with any
changes in the trunk?
39. 43
FEATURE BRANCHING
Always Unit Tested
Daily Merges from
Trunk
Always in releasable state
Always Unit Tested
Trunk
Feature A
Feature B
One widely used solution is to pull from the trunk daily. Any
conflicts can be solved locally by the developer.
40. 44
FEATURE BRANCHING
Always Unit Tested
Daily Merges from
Trunk
Always in releasable state
Always Unit Tested
Trunk
Feature A
Feature B
However, in the current system, merges back to trunk
happen only when the feature is completed.
41. 45
FEATURE BRANCHING
Always Unit Tested
Daily Merges from
Trunk
Boom!
Always in releasable state
Integrating the
code back to
trunk is
inevitably a big-
bang effort.
Always Unit Tested
Trunk
Feature A
Feature B
And that gets messy.
43. 47
FEATURE BRANCHING
Always Unit Tested
Daily Merges from
Trunk
Boom!
Always in releasable state
Unless…
Always Unit Tested
Trunk
Feature A
Feature B
By waiting days or weeks until you merge back, you create a
job of unnecessarily large batch size – a bottleneck.
Integrating the
code back to
trunk is
inevitably a big-
bang effort.
44. 48
CONTINUOUS INTEGRATION
Trunk
Feature A
Always Unit Tested
Feature B
Always in releasable state
Code is merged back to
trunk on a daily basis.
Always Unit Tested
! !
Integration is re-tested
every day. Problems are
caught earlier. Batch size
is smaller.
Once you get to this point, you do not need any branching
45. 49
Before we all take a flying leap into the
great unknown of continuous integration,
let’s consider the situations in which
doing this won’t work.
JOURNEY TO CI
Photo by Reid Naaykens on Unsplash
46. 50
This is Bob
His new code
changes how we
accept orders.
HOW TO BREAK AN INTEGRATION
This is Gina
Her code re-
categorizes
products.
When they integrate
their code to trunk
that evening…
47. 51
Bob’s code is using the old product object code, so it breaks.
Gina’s code assumes the old order workflow, so it breaks.
The system is down. Angry emails circulate. Dogs start barking.
HOW TO BREAK AN INTEGRATION
48. 52
In order to be delivering continuous integration, we must, at a
minimum, do the following:
• Hide new functionality until it is finished.
• Allow incremental changes to be merged into trunk, even if it’s
currently in an unusable state.
• Again, this depends on TDD/BDD! The
behavior of your code must be
predictable.
HOW TO BREAK AN INTEGRATION
50. 54
At its simplest, a feature flag wraps new functionality in an if/then
structure in order to control its release.
if ( featureExists(“newOrder”)) {
// use the new order/product logic
} else {
// use the old logic
}
WHAT IS A FEATURE FLAG?
51. 55
Even better would be to create a new implementation, and to use
a factory method to control implementation at run time.
WHAT IS A FEATURE FLAG?
if ( featureExists(“newOrder”)) {
// inject the new implementation
} else {
// inject the old implementation
}
NewClass
OldClass
52. 56
TRUNK-BASED DEVELOPMENT
Trunk
Includes
Features
A and B
Feature A
Feature B
Always in deployable state
Code is checked into
trunk.
! !
Feature is switched on,
which releases it to
users. Release is
separated from
deployment.
Feature flags remove the need for branching.
55. 64
”Hi! Should we wash our
hands before your
operation? What do you
think?”
BUT OUR MANAGERS WON’T LET US!
By the end of this course, you should
understand why development teams do
not need permission to implement
TDD/BDD.
• Automated test-first practices are not
not optional.
• They are a professional duty of care.
56. 65
Maintenance costs for software are between 40% to 80% of total
cost. Many companies myopically optimize for speed through
development phase but neglect the waste that this creates.
IT WILL SLOW US DOWN!
57. 66
Even though BDD feels like it’s slowing you
down, its overall, long-term effect is to speed
you up.
You literally cannot do Continuous Delivery
without solid automated testing.
According to Accelerate, test automation
predicts better IT performance when:
1. Tests are reliable: the team trusts that when
the tests pass, the software is releasable
2. The tests are created by the team, not by an
outside vendor or a siloed QA organization.
BDD’s IMPACT ON DELIVERY SPEED
58. 67
Again, the benefits of true Continuous Integration
and Continuous Deployment far outweigh short-
term costs.
• 44% more time spent on new features
• 50% higher market cap growth over 3 years
• 8000x faster deployment lead time
• 50% less time spent fixing security defects
• 50% lower change-failure rate
• 21% less time spent on unplanned work and
rework
YOU CAN’T AFFORD NOT TO USE BDD