Top Banner
Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber HUSTEF 2016, Budapest 24/10/2016 Gáspár Nagy coach • trainer • bdd addict • creator of specflow @gasparnagy • [email protected]
46

Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Apr 14, 2017

Download

Software

Gáspár Nagy
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber

HUSTEF 2016, Budapest24/10/2016

Gáspár Nagycoach • trainer • bdd addict • creator of specflow @gasparnagy • [email protected]

Page 2: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

bdd addict

given.when.then

CAUTION!

bddaddict.com

on the stage

Page 3: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

What is BDD?

Page 4: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © 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

Classic model

Page 5: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © 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

CollaborationAutomation with

Cucumber/SpecFlow

BDD Process

Page 6: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

Test Driven Development

Failing test Make it pass

Make it clean

Page 7: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

TDD Cycle

Red Green

Refactor

Page 8: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

How can I apply this to legacy apps?

Page 9: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

Working with a legacy app is like renovating a house…

Page 10: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Renovation can be challenging…

Source: http://kadarkocka.blogspot.com/2011_08_01_archive.html

Page 11: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

My Story

The project was delivered in cooperation with TechTalk (www.techtalk.at)

Page 12: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

It was modern…

Source: http://irodahaz.info

Page 13: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Complex domain…

Page 14: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

106 failing (integration?) tests

Page 15: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

… and other challenges

• 17 GB test database

• 46 projects

• 300k lines of code

• >2 minutes build time

Page 16: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

What can I do with this?

Page 17: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

Page 18: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Source: Wikipedia

Page 19: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

The first change request

Page 20: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Deployment –Workflow

Page 21: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Change request

Source: http://irodahaz.info

We need to replace

that window up

there!

Page 22: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

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 23: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Get the infrastructure ready

Source: http://hfsaustralia.com.au/storage.html

Page 24: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

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 25: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

TDD Cycle

Red Green

Refactor

Page 26: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

1. Capture current behaviorRed

Page 27: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

2. Automate “Then” steps

• Feel free to hard-wire concrete data (IDs)!

Red

Page 28: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

3. Automate “When” with hard-wired data

• We have something to start with!

• (But its obviously nasty with “2347599”)

Green

Page 29: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

Page 30: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

We’ve got a scaffolding!

Source: Wikipedia

Page 31: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

We need to get rid of the hard-wired data!

Page 32: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

1

2

3

4

5

8

9

#6

7

Page 33: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Remove a bit of scaffolding

Page 34: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

4. Pick off a bite!

1

2

3

4

5

8

9

#6

7

Aut

#

#’

Page 35: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

4. Pick off a biteRefactor

Page 36: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

Page 37: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

We have scaffolded our application for implementing this feature!

Page 38: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

5. Describe the new featureRed

Page 39: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

6. Automate and implement it

• You can even forget that your are maintaining a legacy app here…

Green

Page 40: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

7. 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 41: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

Red Green

Refactor

Page 42: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

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 43: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

The strategy also works for bugs

1. Capture current behavior

2. Describe bug as a scenario

3. Fix the bug

Page 44: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

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!

As you learn more, the scaffolding can be removed…

Page 45: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Copyright © Gaspar Nagy

Happy maintenance!

Page 46: Scaffolding a legacy app with BDD scenarios using SpecFlow/Cucumber (HUSTEF 2016, Budapest, 24/10/2016)

Gáspár Nagycoach • trainer • bdd addict • creator of specflow

@gasparnagy • [email protected]

Thank you!

bddaddict.com