Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)
-
Upload
gaspar-nagy -
Category
Software
-
view
625 -
download
0
Transcript of Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)
![Page 1: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/1.jpg)
Gáspár Nagycoach • trainer • bdd addict • creator of specflow
@gasparnagy • [email protected]
Introducing BDD to Legacy Applications
with SpecFlow/Cucumber
Agilia Conference 2016 • 6/4/2016
![Page 2: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/2.jpg)
Copyright © Gaspar Nagy
bdd addict
given.when.then
CAUTION!
bddaddict.com
on the stage
![Page 3: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/3.jpg)
Copyright © Gaspar Nagy
What is BDD?
![Page 4: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/4.jpg)
Copyright © Gaspar Nagy
BDD =
Product Ownership +
Collaboration +
Automationon the product
of requirements
real
![Page 5: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/5.jpg)
Copyright © Gaspar Nagy
Smart Calculator
Demo: BDD Drives Development
![Page 6: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/6.jpg)
Copyright © Gaspar Nagy
How can I apply this to legacy apps?
![Page 7: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/7.jpg)
Copyright © Gaspar Nagy
Working with a legacy app is like renovating a house…
![Page 8: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/8.jpg)
Renovation can be challenging…
Source: http://kadarkocka.blogspot.com/2011_08_01_archive.html
![Page 9: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/9.jpg)
Copyright © Gaspar Nagy
My Story
The project was delivered in cooperation with TechTalk (www.techtalk.at)
![Page 10: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/10.jpg)
It was modern…
Source: http://irodahaz.info
![Page 11: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/11.jpg)
Complex domain…
![Page 12: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/12.jpg)
106 failing (integration?) tests
![Page 13: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/13.jpg)
Copyright © Gaspar Nagy
… and other challenges
• 17 GB test database
• 46 projects
• 300k lines of code
• >2 minutes build time
![Page 14: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/14.jpg)
Copyright © Gaspar Nagy
What can I do with this?
![Page 15: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/15.jpg)
Copyright © Gaspar Nagy
![Page 16: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/16.jpg)
Source: Wikipedia
![Page 17: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/17.jpg)
Copyright © Gaspar Nagy
The first change request
![Page 18: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/18.jpg)
Deployment –
Workflow
![Page 19: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/19.jpg)
Copyright © Gaspar Nagy
0. Get the infrastructure ready
We need a healthy local dev and CI environment!
• Make a dummy test and get it running!
• Ignore/skip/delete unstable
tests
• Setup the desired testing
model (e.g. SpecFlow)
• Test core dependencies
(e.g. “When I do
something with the
database”)
![Page 20: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/20.jpg)
Copyright © Gaspar Nagy
1. Capture current behavior
• Based on the way it was demoed to you
• Do not worry about automation
• Do not worry about details
• Do not worry about exact phrasing
![Page 21: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/21.jpg)
Copyright © Gaspar Nagy
TDD Cycle
![Page 22: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/22.jpg)
Copyright © Gaspar Nagy
ATDD Cycle
![Page 23: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/23.jpg)
Copyright © Gaspar Nagy
1. Capture current behaviorRed
![Page 24: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/24.jpg)
Copyright © Gaspar Nagy
2. Automate “Then” steps
• Feel free to hard-wire concrete data (IDs)!
Red
![Page 25: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/25.jpg)
Copyright © Gaspar Nagy
3. Improve errors
Our scenario fails. Is it easy to understand why?
• Check the test output and improve if necessary!
Red
![Page 26: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/26.jpg)
Copyright © Gaspar Nagy
![Page 27: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/27.jpg)
Copyright © Gaspar Nagy
4. Automate “When” with hard-wired data
• We have something to start with!
• (But its obviously nasty with “2347599”)
Green
![Page 28: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/28.jpg)
Copyright © Gaspar Nagy
![Page 29: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/29.jpg)
Copyright © Gaspar Nagy
We need to get rid of the hard-wired data!
![Page 30: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/30.jpg)
1
2
3
4
5
8
9
#6
7
![Page 31: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/31.jpg)
5. Pick off a bite!
1
2
3
4
5
8
9
#6
7
Aut
#
#’
![Page 32: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/32.jpg)
Copyright © Gaspar Nagy
5. Pick off a biteRefactor
![Page 33: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/33.jpg)
Copyright © Gaspar Nagy
![Page 34: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/34.jpg)
Copyright © Gaspar Nagy
We have scaffolded our application for implementing this feature!
![Page 35: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/35.jpg)
Copyright © Gaspar Nagy
6. Describe the new featureRed
![Page 36: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/36.jpg)
Copyright © Gaspar Nagy
7. Automate and implement it
• You can even forget that your are maintaining a legacy app here…
Green
![Page 37: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/37.jpg)
Copyright © Gaspar Nagy
8. Discover corner cases
• We have seen a “happy path” so far…
• But what happens if…• …there are associated deliverables
• …the package is partially frozen
• …
![Page 38: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/38.jpg)
Copyright © Gaspar Nagy
9. Pick low hanging fruits
• We have developed an automation interface for a part of the application
• Can we use it to cover other usual cases?
![Page 39: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/39.jpg)
Copyright © Gaspar Nagy
![Page 40: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/40.jpg)
Copyright © Gaspar Nagy
Summary: The first change request
• We addressed the system through a new feature
• Ensured that the test infrastructure works
• Scaffolded the app with a test for the current behavior using hard wired data
• Refactored the automation to eliminate some parts of these data – taken apart a bit of the scaffolding
• Described and implemented the new feature
• Used the automation infrastructure for further tests
![Page 41: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/41.jpg)
Copyright © Gaspar Nagy
The first bug
![Page 42: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/42.jpg)
Copyright © Gaspar Nagy
This is a nasty bug…
• Because• Workflow is handled by WF 3
• Script is executed on a remote machine through SSH
• A very old dead OSS project is used for SSH (no timeout setting)
• I cannot even try this out!
![Page 43: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/43.jpg)
Copyright © Gaspar Nagy
Ok… calm down.
We have a process…
![Page 44: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/44.jpg)
Copyright © Gaspar Nagy
1. Capture current behavior
• Do not worry about automation
• Do not worry about details
• Do not worry about exact phrasing
Red
![Page 45: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/45.jpg)
Copyright © Gaspar Nagy
2. How to test SSH?
A focused scenario can drive you to find a solution for automation
• Find a tool that can be well automated and can be used for SSH – Vagrant?
• Set it up locally (don’t worry about the automation yet)
• Make the test pass with the local setup• Do you remember deployment #2347599?
• Refactor: Eliminate hard-wired details
Green
![Page 46: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/46.jpg)
Copyright © Gaspar Nagy
3. Describe bug as a scenario
Red
![Page 47: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/47.jpg)
Copyright © Gaspar Nagy
4. Fix the bug!
• With the test we could find the bug that was actually in the SSH library
Green
![Page 48: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/48.jpg)
Copyright © Gaspar Nagy
Shall we keep regression tests?
• It depends…
• If the bug highlighted an important business case –keep it!
• If it described a special situation (and the bugfix was covered by unit/integration tests) – delete it!
• Maintaining regression tests is very costly!
![Page 49: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/49.jpg)
Copyright © Gaspar Nagy
![Page 50: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/50.jpg)
Copyright © Gaspar Nagy
Summary: The first bug
• Similarly to new features, addressing the bugs by capturing the current behavior as scenarios is helpful
• Don’t be afraid of deleting the regression test after fixing the bug if it does not represent an important business case
![Page 51: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/51.jpg)
Copyright © Gaspar Nagy
Working on a legacy app does not mean that you cannot apply BDD
process.
The scenarios can guide you to discover more and more from the
application!
![Page 52: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/52.jpg)
Copyright © Gaspar Nagy
Happy maintenance!
![Page 53: Introducing BDD to Legacy Applications with SpecFlow/Cucumber (Agilia Conference 2016)](https://reader031.fdocuments.us/reader031/viewer/2022022201/589d38f31a28abd17d8b5eb7/html5/thumbnails/53.jpg)
Gáspár Nagycoach • trainer • bdd addict • creator of specflow
@gasparnagy • [email protected]
Thank you!