Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)

292 views

Published on

Do you remember your childhood when your mom or an older story teller pronounced the most interesting words in the world? “Once upon a time…” Let me be now your story teller, listen to my story about a legacy app, a painful problem, the search for the solution and the lucky outcome.

No, no, this is not the story about a new green field project where everything is so clear. However, even in this story there is a master builder, who shows the developers how to scaffold the legacy app with BDD scenarios using SpecFlow or Cucumber and everything will be all right in the end. Let me tell you about different strategies, collaboration and testing patterns that can be followed in such a renovation-like situation.

So, are you ready...? “Once upon a time there was a company where…” To be continued at my session...

Published in: Software
  • Be the first to comment

Scaffolding a legacy app with BDD scenario (Agile in the City Bristol 2017)

  1. 1. Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber Agile in the City Bristol 2017 2nd November, 2017 Gáspár Nagy coach • trainer • bdd addict • creator of specflow “The BDD Books: Discovery” • http://bddbooks.com @gasparnagy • gaspar@specsolutions.eu
  2. 2. Copyright © Gaspar NagyCopyright © Gaspar Nagy bdd addict given.when.then CAUTION! on the stage Gáspár Nagy coach, trainer and bdd addict creator of SpecFlow gaspar@specsolutions.eu https://specsolutions.eu @gasparnagy
  3. 3. Copyright © Gaspar NagyCopyright © Gaspar Nagy Check out our new book! • A BDD book for everyone (PO, BA, dev, tester) • Practical guide • Demonstrates good collaboration techniques, illustrated by concrete examples Find it on Leanpub through http://bddbooks.com!
  4. 4. Copyright © Gaspar NagyCopyright © Gaspar Nagy Agenda • BDD, how I see it • Challenges of legacy apps • Concept of scaffolding through an example • Fixing a bug & placing it on the testing pyramid
  5. 5. Copyright © Gaspar NagyCopyright © Gaspar Nagy What is BDD?
  6. 6. Copyright © Gaspar NagyCopyright © Gaspar Nagy [HttpPost] public ActionResult Answer(int answer) { TriviaEntities db = new TriviaEntities(); var question = db.FindQuestion(CurrentQuestion); if (question.Type == QuestionType.Easy) { db.AddScore(question, user, 10); } else { db.AddScore(question, user, 50); } var model = new GameModel { Score = db.GetScore(question, user) }; return View(model); } implement feedback Agile mini-waterfall
  7. 7. Copyright © Gaspar NagyCopyright © Gaspar Nagy Examples link requirements to software
  8. 8. Copyright © Gaspar NagyCopyright © Gaspar Nagy Scenario: Correct easy answer scores 10 Given I register a team When I submit a correct easy answer Then my score should be 10 Discovery Automation with Cucumber/SpecFlow Examples link requirements to software Formulation
  9. 9. Copyright © Gaspar NagyCopyright © Gaspar Nagy So, what is BDD? Discovery Shared understanding is established through collaboration and structured conversations Formulation Examples of system behaviour are documented as scenarios Automation Scenarios are automated to be able to verify the system’s behaviour
  10. 10. Copyright © Gaspar NagyCopyright © Gaspar Nagy BDD “drives” development Passing scenario Failing scenario Refactor
  11. 11. Copyright © Gaspar NagyCopyright © Gaspar Nagy The TDD Cycle GreenRed Refactor
  12. 12. Copyright © Gaspar NagyCopyright © Gaspar Nagy How can I apply this to legacy apps?
  13. 13. Copyright © Gaspar NagyCopyright © Gaspar Nagy Working with a legacy app is like renovating a house…
  14. 14. Renovation can be challenging… Source: http://kadarkocka.blogspot.com/2011_08_01_archive.html
  15. 15. Copyright © Gaspar NagyCopyright © Gaspar Nagy My Story The project was delivered in cooperation with TechTalk (www.techtalk.at)
  16. 16. My legacy app project… Source: http://irodahaz.info
  17. 17. Complex domain…
  18. 18. 106 failing (integration?) tests
  19. 19. Copyright © Gaspar NagyCopyright © Gaspar Nagy … and other challenges • 17 GB test database • 46 projects • 300k lines of code • >2 minutes build time
  20. 20. Copyright © Gaspar NagyCopyright © Gaspar Nagy What can I do with this?
  21. 21. Copyright © Gaspar NagyCopyright © Gaspar Nagy
  22. 22. Source: Wikipedia
  23. 23. Copyright © Gaspar NagyCopyright © Gaspar Nagy The first change request
  24. 24. Deployment – Workflow
  25. 25. Change request Source: http://irodahaz.info We need to replace that window up there!
  26. 26. 0. Get the infrastructure ready Source: http://hfsaustralia.com.au/storage.html
  27. 27. Copyright © Gaspar NagyCopyright © Gaspar Nagy 0. Get the infrastructure ready We need a healthy local dev and CI environment! • Make a dummy test and get it running! • Setup the desired testing model (e.g. SpecFlow) • Automated the scenario to exercise the app with it’s dependencies (e.g. database) • Ignore/skip/delete unstable tests
  28. 28. Copyright © Gaspar NagyCopyright © Gaspar Nagy 1. Capture current behavior • Based on the way it was explained by the client • We did not worry about automation • We did worry about details
  29. 29. Copyright © Gaspar NagyCopyright © Gaspar Nagy The TDD Cycle GreenRed Refactor
  30. 30. Copyright © Gaspar NagyCopyright © Gaspar Nagy 1. Capture current behavior Red
  31. 31. Copyright © Gaspar NagyCopyright © Gaspar Nagy 2. Automate “Then” steps • Feel free to hard-wire concrete data (IDs)! Red
  32. 32. Copyright © Gaspar NagyCopyright © Gaspar Nagy 3. Automate “When” with hard-wired data • We have something to start with! • (But its obviously nasty with “2347599”) Green
  33. 33. Copyright © Gaspar NagyCopyright © Gaspar Nagy It’s passing, although we haven’t done anything for the “Given”…
  34. 34. We’ve got a scaffolding! Source: Wikipedia
  35. 35. Copyright © Gaspar NagyCopyright © Gaspar Nagy We need to get rid of the hard-wired data!
  36. 36. 1 2 3 4 5 8 9 #6 7
  37. 37. Remove a bit of scaffolding
  38. 38. 4. Pick off a bite! 1 2 3 4 5 8 9 #6 7 Aut # #’
  39. 39. Copyright © Gaspar NagyCopyright © Gaspar Nagy 4. Pick off a bite Refactor
  40. 40. Copyright © Gaspar NagyCopyright © Gaspar Nagy We have a test now for the current behavior… Let’s implement the feature!
  41. 41. Copyright © Gaspar NagyCopyright © Gaspar Nagy We have scaffolded our application for implementing this feature!
  42. 42. Copyright © Gaspar NagyCopyright © Gaspar Nagy 5. Describe an example of the new feature Red
  43. 43. Copyright © Gaspar NagyCopyright © Gaspar Nagy 6. Automate and implement it! • You can even forget that your are maintaining a legacy app here… Green
  44. 44. Copyright © Gaspar NagyCopyright © Gaspar Nagy GreenRed Refactor We not only made it, but… • We established a CI/CD pipeline • We cleared out a misunderstanding before implementing the change • We created a few reusable automation steps
  45. 45. Copyright © Gaspar NagyCopyright © Gaspar Nagy BDD for implementing a 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 adding further tests
  46. 46. Copyright © Gaspar NagyCopyright © Gaspar Nagy Let’s fix a bug!
  47. 47. Copyright © Gaspar NagyCopyright © Gaspar Nagy The first bug
  48. 48. Copyright © Gaspar NagyCopyright © Gaspar Nagy GreenRed Refactor We not only made it, but… • We isolated the issue • We solved a testing challenge that was even a problem for manual testing • We covered another area of the application with tests • We created again a few more reusable automation steps
  49. 49. Copyright © Gaspar NagyCopyright © Gaspar Nagy Shall we keep this scenario?
  50. 50. Copyright © Gaspar NagyCopyright © Gaspar Nagy Shall we keep this scenario? • Special context • The app gets to an inconsistent state (workflow stopped, script running) • The bug was in the SSH library
  51. 51. Copyright © Gaspar NagyCopyright © Gaspar Nagy Pic: http://gasparnagy.com/2017/02/balancing-scenarios-and-unit-tests-case-study-with-specflow/ Timeout Scenario
  52. 52. Copyright © Gaspar NagyCopyright © Gaspar Nagy A classification of quality aspects Functional • Works as expected • Expectations are good • Expectations are documented Usability • Secure • Fast • Convenient • Pretty • Consistent • Predictable Strategic • Architecture • Code quality • Easy to integrate • Flexible
  53. 53. Copyright © Gaspar NagyCopyright © Gaspar Nagy Pic: http://gasparnagy.com/2017/02/balancing-scenarios-and-unit-tests-case-study-with-specflow/ Timeout Scenario Srv-UI Functional Usability Strategic Edge case Argument check Timeout Test Happy Path Func1 Func2
  54. 54. Copyright © Gaspar NagyCopyright © Gaspar Nagy Functional Usability Strategic Forrás: http://gasparnagy.com/2017/02/balancing-scenarios-and-unit-tests-case-study-with-specflow/ Happy path Srv-UI Edge case Argument check Ext call timeout Func1 Func2
  55. 55. Copyright © Gaspar NagyCopyright © Gaspar Nagy Srv-UI Functional Usability Strategic Edge case Argument check Ext call timeout Forrás: http://gasparnagy.com/2017/02/balancing-scenarios-and-unit-tests-case-study-with-specflow/ Happy Path Func1 Func2
  56. 56. Copyright © Gaspar NagyCopyright © 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 – delete it! • And cover the root cause with technical tests • Maintaining regression scenarios is costly!
  57. 57. Copyright © Gaspar NagyCopyright © 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! As you learn more, the scaffolding can be removed…
  58. 58. Copyright © Gaspar NagyCopyright © Gaspar Nagy Happy maintenance!
  59. 59. Gáspár Nagy coach • trainer • bdd addict • creator of specflow @gasparnagy • gaspar@specsolutions.eu Thank you! http://bddbooks.com

×