Moving away from legacy code with BDD
Jul 16, 2015
BDD Evangelist
BDD Practice Manager @Inviqa
Creator of Behat, Mink, PhpSpec2, Prophecy
Contributor to Symfony2, Composer
@everzet
This talk is about
• Solving purely technical “TCIAM” problem using behavioural business analysis and discovery process
• Building a delivery strategy on the idea of the change appreciation
• Real-life experience
This talk is not about
• Greenfield projects
• Maintenance-mode projects
• Solutions for everyone
• How to write code
If the project can afford at least one full-time specialist on a payroll that whines how horrible this project is, then surely it did something right.
This world is full of brilliant projects that nobody wants to whine about. Sadly, it’s often simply because there’s no one left to pay for that.
• Great value + Awful code = Great product today
• Great value + Great code = Great product tomorrow
• No value + Any kind of code= Awful product anytime
• Great value + Awful code = Great product today
• Great value + Great code = Great product tomorrow
• No value + Any kind of code= Awful product anytime
Three popular options
1. Rewrite an entire application using “the right way”
2. Do technical refactoring
3. Do business-oriented rewrite using “BDD pipeline”
#1: Full Rewrite
• Scrum / Kanban
• TDD / BDD / DDD / Other XP goodness
• New everything
• Mirroring functionality
#1: Full Rewrite
Just spaghetti, please: 4 man years
Full London meal (TDD, BDD, Agile, QA): ??? man years
#2: Technical Refactoring
• Blackbox testing
• New routing
• New templating system
• Migration of model layer (MySQL -> Mongo)
• Whatever else that is easy to replace
Questionnaire
1. Where is this project going?
2. Which features are going to change?
3. How are they going to change?
4. How to support that change?
“BDD Pipeline”
1. Where is this project going?
2. Which features are going to change?
3. How are they going to change?
4. How to support that change?
• Impact Mapping
• Business Prioritisation
• Example (3 Amigos) Workshop
• BDD layers
– Gojko Adzic
“Impact mapping is a strategic planning technique that prevents organisations from getting lost
while building products and delivering projects, by clearly communicating assumptions, helping teams align their activities with overall business objectives and make better roadmap decisions.”
Four levels of Impact Map
1. Why? are we doing all this (rewrite)? What is the goal we’re trying to achieve?
2. Who? will be impacted by it?
3. How? can they help us to achieve the goal?
4. What? can we do to support them?
In order to buy more products As a customer I need to have a product autocompletion in the search field
In order to maintain my shopping history As a site visitor I need to be able to register on this site
In order to maintain my shopping history As a site visitor I need to be able to register on this site
benefit
actor
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Scenario: Replaced items should be returned to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Scenario: ...
Scenario: Replaced items should be returned to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Scenario: ...
Scenario: ...
Scenario: ...
Scenario: ...
Scenario: ...
Scenario: Replaced items should be returned to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Given a customer previously bought a black sweater from me And I currently have three black sweaters left in stock When he returns the sweater for a refund Then I should have four black sweaters in stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Given a customer previously bought a black sweater from me And I currently have three black sweaters left in stock When he returns the sweater for a refund Then I should have four black sweaters in stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Step#2: Discuss old logic
1. What should this thing do
2. What if it suddenly stops doing it?
3. How would you know if it doesn't work?
4. How would you know if it does?
Step#3: Prepare for A change
1. Cover old behaviour in an end-to-end fashion
2. Make sure that scenarios/tests are green
3. Refactor code to make the upcoming change easier
4. Make scenarios/tests green
Step#0: Prepare for any change
1. Prepare the application infrastructure for bridging
a. Share sessions
b. Share data
2. Prepare the server infrastructure for bridging