PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation...
Transcript of PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation...
![Page 1: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/1.jpg)
Budapest, 26-28 October 2016
PROPERTY BASED BDD EXAMPLESPresented by Gaspar Nagy
© All rights reserved
[email protected]@gasparnagy, http://gasparnagy.com
![Page 2: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/2.jpg)
BDD PBT
• Behavior Driven Development
• ~Specification by Example (SbE)
• ~Acceptance Test Driven Development (ATDD)
• ~Keyword Driven Testing
2 © All rights reserved
• Property Based Testing
• Property Testing• ~Random Testing• ~Model‐based Testing
![Page 3: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/3.jpg)
[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
What is BDD? – Classic model
![Page 4: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/4.jpg)
Scenario: Correct easy answer scores 10Given I register a teamWhen I submit a correct easy answerThen my score should be 10
Collaboration Automation with Cucumber/SpecFlow
What is BDD?
![Page 5: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/5.jpg)
This is an example!
5 © All rights reserved
Scenario: Correct easy answer scores 10Given I register a teamWhen I submit a correct easy answerThen my score should be 10
![Page 6: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/6.jpg)
How many examples you need?
6 © All rights reserved
Scenario: Add two numbersGiven I have entered 1 into the calculatorAnd I have entered 2 into the calculatorWhen I press addThen the result should be 3 on the screen
Scenario: Add two numbersGiven I have entered 5 into the calculatorAnd I have entered ‐7 into the calculatorWhen I press addThen the result should be ‐2 on the screen
Scenario: Add two numbersGiven I have entered 2 into the calculatorAnd I have entered 0 into the calculatorWhen I press addThen the result should be 2 on the screen
![Page 7: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/7.jpg)
Scenario Outlines
7 © All rights reserved
Scenario Outline: Add two numbersGiven I have entered <a> into the calculatorAnd I have entered <b> into the calculatorWhen I press addThen the result should be <result> on the screen
Examples:| a | b | result || 1 | 2 | 3 || 5 | ‐7 | ‐2 || 2 | 0 | 2 |
![Page 8: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/8.jpg)
BDD is for…
understanding & validating
business requirements
through illustrative examples
8 © All rights reserved
![Page 9: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/9.jpg)
PBT is for…
verifying
implementation
through checking statements about the
output for many different possible inputs
9 © All rights reserved
source: http://blog.jessitron.com/2013/04/property-based-testing-what-is-it.html
the “properties”
![Page 10: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/10.jpg)
For example for addition…
• Commutative property: a + b = b + a• Associative property: (a + b) + c = a + (b + c)• Identity property: a + 0 = a• Distributive property: a * (b + c) = a*b + a*c
We would like to verify these for ~ALL input combinations!
10 © All rights reserved
![Page 11: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/11.jpg)
There is a tool for doing this!
• QuickCheck (Haskell) is the canonical framework, but there are many different ports of it to other programming languages• QuickCheck for Java• PhpQuickCheck for PHP• ScalaCheck for Scala• FsCheck for .NET (F#, C#)• … (see more at https://en.wikipedia.org/wiki/QuickCheck)
11 © All rights reserved
![Page 12: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/12.jpg)
FsCheck Sample
12 © All rights reserved
![Page 13: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/13.jpg)
When the implementation is wrong…
13 © All rights reserved
![Page 14: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/14.jpg)
BDD PBT
• 1 + 2 = 3• 5 + ‐7 = ‐2• 2 + 0 = 2
14 © All rights reserved
• Commutative• Associative• Identity• Distributive
![Page 15: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/15.jpg)
Examples in SpecFlow
15 © All rights reserved
![Page 16: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/16.jpg)
Identity property BDD style…
16 © All rights reserved
![Page 17: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/17.jpg)
Defining constraints and expectations…
17 © All rights reserved
![Page 18: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/18.jpg)
More real life examples…
18 © All rights reserved
![Page 19: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/19.jpg)
Summary
• BDD turns examples into automated tests• PBT automates rules with many different input
• The power of this two can be combined to achieve an executable specification
• The BDD and the PBT tools can work together for this• See http://github.com/gasparnagy/SpecFlow.FsCheck
19 © All rights reserved
![Page 20: PROPERTY BASED BDD EXAMPLES - ETSI · 2016-11-17 · PROPERTY BASED BDD EXAMPLES ... Automation with Cucumber/SpecFlow What is BDD? This is an example! 5 ©Allrightsreserved Scenario:](https://reader030.fdocuments.in/reader030/viewer/2022040308/5ed9f7ed28db2d5ca2492b86/html5/thumbnails/20.jpg)
[email protected]@gasparnagyhttp://gasparnagy.com
© All rights reserved
Special thanks to • Ciaran McNulty• Konstantin Kudryashov