SlideShare una empresa de Scribd logo
1 de 50
Descargar para leer sin conexión
Behaviour Driven Development
  and thinking about testing



           Malcolm Tredinnick
      malcolm.tredinnick@gmail.com
Why have I asked you here today?


     1) Testing landscape
     2) A different way to think about this
     3) Code
Chapter I: The Testing Landscape
Isolated   Integrated
Isolated                           Integrated


        Testing unit            External service
           size?                  availability
Mocks
                       Running time?
Mocks
●   Substitute for external systems & components
●   Need to be injected into the tests
    ●   “Monkey patching”
    ●   Dependency injection
Monkey patching


import socket

def setUp(...):
   socket.socket = DummySocketObject
   ...
Mocks
●   Substitute for external systems & components
●   Need to be injected into the tests
    ●   “Monkey patching”
    ●   Dependency injection
●   Need to be kept in synch with reality!
Isolated                    Integrated




           Infrastructure
ce
                                     n
                                e na
                             nt
                             ai
                            M
Isolated                           Integrated




           Infrastructure
Testing Strategies




   Some of many...
Testing Strategies
●   Formal verification
Testing Strategies
●   Formal verification
●   Test everything you can think of
Testing Strategies
●   Formal verification
●   Test everything you can think of
●   Anti-regression suite
      No bug fix without a test
Testing Strategies
●   Formal verification
●   Test everything you can think of
●   Anti-regression suite
●   Test driven development (TDD)
TDD


1.Write a (failing) test for next method or class
2.Write minimal code to make test pass
3.Rinse, wash, repeat.
Testing Strategies
●   Formal verification
●   Test everything you can think of
●   Anti-regression suite
●   Test driven development (TDD)
      “Specification, not verification”
Testing Strategies
●   Formal verification
●   Test everything you can think of
●   Anti-regression suite
●   Test driven development (TDD)
●   Documentation driven development (DDD?)
Testing Strategies
●   Formal verification
●   Test everything you can think of
●   Anti-regression suite
●   Test driven development (TDD)
●   Documentation driven development (DDD?)
●   Behaviour driven development (BDD)
Chapter II: A different way of thinking
Interlude: Creating systems...
Interlude: Creating systems...



          Specification
Interlude: Creating systems...

        Specification




                    Implementation

         Testing
Specification

●   On (e-)paper?
    ●   quick sketch
    ●   formal requirements document
    ●   mailing list discussion
●   In your head?
Specification



●   Capturing the idea is probably good
●   “What was I thinking smoking when...?”
Specification


As a [user or role],

I want [feature]

so that [something happens]
Specification


As a maze creator,

I want to be able to specify dimensions

so that a new maze of the given size is created.
BDD



What is the next most important
thing the code should do?
BDD



     What is the next most important
     thing the code should do?



Be able to
test this...              ... then implement it.
Scenario


Given that [initial context],

if and when [some event occurs]

then [ensure some outcomes]
Use case versus scenario


As a [user or role],          Given that [initial context],

I want [feature]              if and when [some event occurs]

so that [something happens]   then [ensure some outcomes]
Chapter III: Concrete code
Interlude: Naming things


 Language helps guide our brain.
 Focuses the mind.
 Perhaps too exclusively.
Interlude: Naming things


The Sapir-Whorf Hypothesis:
“[...] the structure of a language affects the ways in
which its speakers are able to conceptualise their
world [view].”
Example #1: Python's unittest module
Test titles
class BasicFieldTests (TestCase):
  def test_field_name (self):
    ...


  def test_show_hidden_initial (self):
    ...
Test titles
class Fields (TestCase):
  def should_allow_name_override (self):
     ...


class ChoiceFields (TestCase):
  def should_permit_initial_values_in_hidden_widgets (self):
     ...
Run new test titles


Write a load_test() method to pull out
all the “should” methods.

(Easy enough, but a few lines of code.)
Matching to scenarios
●   Typically, end up creating more classes than
    unittests (not a bad thing; classes are “free”).
    ●   Thinking about test names helps with class names
        and roles.
●   Context setup is done in setUp() method.
●   Normal unittest assertions work fairly cleanly.
Example #2: Doctests
Narrative style testing
Jane created a new maze with a small (5 x 5) size.

>>> from maze import Maze
>>> maze = Maze(5, 5)

Spot, her dog, did not think the new maze was the right size, but
Jane was able to convince him like this:

>>> maze.x_size
5
>>> maze.y_size
5

They found the entry and exit locations in their new maze:

>>>maze.entry_cell
(0, 0, “left”)

(etc)
Narrative style testing
●   Excellent if you are truly writing a narrative.
●   Can be difficult to maintain (but not always).
●   Avoid if large amounts of setup required.
●   Use with caution. Do use. Do not abuse.
Example #3: Domain specific languages
DSL packages



●   Lettuce
●   Freshen


                  Both available through PyPI
Freshen example


Scenario: Divide regular numbers
  Given I have entered 3 into the calculator
  And I have entered 2 into the calculator
  When I press divide
  Then the result should be 1.5 on the screen




                        (Code samples from Freshen documentation)
Backing code

from freshen import *

import calculator

@Before
def before(unused):
    scc.calc = calculator.Calculator()
    scc.result = None

@Given("I have entered (d+) into the calculator")
def enter(num):
    scc.calc.push(int(num))


                         (Code samples from Freshen documentation)
Backing code


@When("I press (w+)")
def press(button):
    op = getattr(scc.calc, button)
    scc.result = op()

@Then("the result should be (.*) on the screen")
def check_result(value):
    assert_equal(str(scc.result), value)




                        (Code samples from Freshen documentation)
Freshen templated example
Scenario Outline: Add two numbers
  Given I have entered <input_1> into the calculator
  And I have entered <input_2> into the calculator
  When I press <button>
  Then the result should be <output> on the screen


Examples:
  | input_1 | input_2 | button | output |
  | 20      | 30      | add    | 50         |
  | 2       | 5       | add    | 7          |
  | 0       | 40      | add    | 40         |


                          (Code samples from Freshen documentation)
Conclusions(?)
●   Behavioural tests are worth trying
●   Question the way you think from time to time
●   Are your tests' purpose clear to future you?
https://github.com/malcolmt/bdd-and-testing-talk




            malcolm.tredinnick@gmail.com
                     @malcolmt

Más contenido relacionado

La actualidad más candente

Web Accessibility Testing Trends and Shift Left Testing of accessibility usin...
Web Accessibility Testing Trends and Shift Left Testing of accessibility usin...Web Accessibility Testing Trends and Shift Left Testing of accessibility usin...
Web Accessibility Testing Trends and Shift Left Testing of accessibility usin...Narayanan Palani
 
Laws of test automation framework
Laws of test automation frameworkLaws of test automation framework
Laws of test automation frameworkvodqancr
 
ISTQB Foundation and Selenium Java Automation Testing
ISTQB Foundation and Selenium Java Automation TestingISTQB Foundation and Selenium Java Automation Testing
ISTQB Foundation and Selenium Java Automation TestingHiraQureshi22
 
Automation testing strategy, approach & planning
Automation testing  strategy, approach & planningAutomation testing  strategy, approach & planning
Automation testing strategy, approach & planningSivaprasanthRentala1975
 
Elements of a Test Framework
Elements of a Test FrameworkElements of a Test Framework
Elements of a Test FrameworkSmartBear
 
London SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingLondon SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingRichard Clark
 
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...Agile Testing Alliance
 
Test Automation Trends and Beyond
Test Automation Trends and BeyondTest Automation Trends and Beyond
Test Automation Trends and BeyondKnoldus Inc.
 
Colorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latestColorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latestOnur Baskirt
 
Introduction to SoapUI day 1
Introduction to SoapUI day 1Introduction to SoapUI day 1
Introduction to SoapUI day 1Qualitest
 
Next Generation Functional & Visual Testing powered by AI
Next Generation Functional & Visual Testing powered by AINext Generation Functional & Visual Testing powered by AI
Next Generation Functional & Visual Testing powered by AIAnand Bagmar
 
Illia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot applicationIllia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot applicationAnna Shymchenko
 
KeytorcTestTalks #11 - Onur Başkirt, Agile Test Management with Testrail
KeytorcTestTalks #11 - Onur Başkirt, Agile Test Management with Testrail KeytorcTestTalks #11 - Onur Başkirt, Agile Test Management with Testrail
KeytorcTestTalks #11 - Onur Başkirt, Agile Test Management with Testrail Keytorc Software Testing Services
 
Visual Testing: The Missing Piece of the Puzzle -- presentation by Gil Tayar
Visual Testing: The Missing Piece of the Puzzle -- presentation by Gil TayarVisual Testing: The Missing Piece of the Puzzle -- presentation by Gil Tayar
Visual Testing: The Missing Piece of the Puzzle -- presentation by Gil TayarApplitools
 
Visual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for DevelopersVisual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for DevelopersSteve Lange
 
Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksŁukasz Morawski
 

La actualidad más candente (20)

Web Accessibility Testing Trends and Shift Left Testing of accessibility usin...
Web Accessibility Testing Trends and Shift Left Testing of accessibility usin...Web Accessibility Testing Trends and Shift Left Testing of accessibility usin...
Web Accessibility Testing Trends and Shift Left Testing of accessibility usin...
 
Laws of test automation framework
Laws of test automation frameworkLaws of test automation framework
Laws of test automation framework
 
ISTQB Foundation and Selenium Java Automation Testing
ISTQB Foundation and Selenium Java Automation TestingISTQB Foundation and Selenium Java Automation Testing
ISTQB Foundation and Selenium Java Automation Testing
 
Automation testing strategy, approach & planning
Automation testing  strategy, approach & planningAutomation testing  strategy, approach & planning
Automation testing strategy, approach & planning
 
Elements of a Test Framework
Elements of a Test FrameworkElements of a Test Framework
Elements of a Test Framework
 
London SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error HandlingLondon SF Developers: Custom Lightning Component Error Handling
London SF Developers: Custom Lightning Component Error Handling
 
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
ATAGTR2017 Keeping pace with Product Evolution: UI Automation Framework Guide...
 
Test Automation Trends and Beyond
Test Automation Trends and BeyondTest Automation Trends and Beyond
Test Automation Trends and Beyond
 
Automated UI Testing
Automated UI TestingAutomated UI Testing
Automated UI Testing
 
Colorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latestColorful world-of-visual-automation-testing-latest
Colorful world-of-visual-automation-testing-latest
 
Speed up your tests
Speed up your testsSpeed up your tests
Speed up your tests
 
Introduction to SoapUI day 1
Introduction to SoapUI day 1Introduction to SoapUI day 1
Introduction to SoapUI day 1
 
How to Introduce Continuous Delivery
How to Introduce Continuous DeliveryHow to Introduce Continuous Delivery
How to Introduce Continuous Delivery
 
Next Generation Functional & Visual Testing powered by AI
Next Generation Functional & Visual Testing powered by AINext Generation Functional & Visual Testing powered by AI
Next Generation Functional & Visual Testing powered by AI
 
Illia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot applicationIllia Seleznov - Integration tests for Spring Boot application
Illia Seleznov - Integration tests for Spring Boot application
 
KeytorcTestTalks #11 - Onur Başkirt, Agile Test Management with Testrail
KeytorcTestTalks #11 - Onur Başkirt, Agile Test Management with Testrail KeytorcTestTalks #11 - Onur Başkirt, Agile Test Management with Testrail
KeytorcTestTalks #11 - Onur Başkirt, Agile Test Management with Testrail
 
Visual Testing: The Missing Piece of the Puzzle -- presentation by Gil Tayar
Visual Testing: The Missing Piece of the Puzzle -- presentation by Gil TayarVisual Testing: The Missing Piece of the Puzzle -- presentation by Gil Tayar
Visual Testing: The Missing Piece of the Puzzle -- presentation by Gil Tayar
 
Bdd and spec flow
Bdd and spec flowBdd and spec flow
Bdd and spec flow
 
Visual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for DevelopersVisual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for Developers
 
Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation Frameworks
 

Destacado

Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016vodqasg
 
Automated Tests in Agile based on Serenity BDD - Michał Szybalski
Automated Tests in Agile based on Serenity BDD - Michał SzybalskiAutomated Tests in Agile based on Serenity BDD - Michał Szybalski
Automated Tests in Agile based on Serenity BDD - Michał SzybalskiŁódQA
 
Serenity BDD - from executable specifications to living documentation
Serenity BDD - from executable specifications to living documentationSerenity BDD - from executable specifications to living documentation
Serenity BDD - from executable specifications to living documentationAlex Soto
 
Behavior Driven Development - Live Webinar
Behavior Driven Development - Live WebinarBehavior Driven Development - Live Webinar
Behavior Driven Development - Live WebinarBelatrix Software
 
Smarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automationSmarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automationRIA RUI Society
 
Model-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next LevelModel-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next LevelBob Binder
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumberDaniel Kummer
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testingdversaci
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and SeleniumNikolay Vasilev
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberKMS Technology
 
[Thong Nguyen & Trong Bui] Behavior Driven Development (BDD) and Automation T...
[Thong Nguyen & Trong Bui] Behavior Driven Development (BDD) and Automation T...[Thong Nguyen & Trong Bui] Behavior Driven Development (BDD) and Automation T...
[Thong Nguyen & Trong Bui] Behavior Driven Development (BDD) and Automation T...Ho Chi Minh City Software Testing Club
 

Destacado (20)

BDD in Automation Testing
BDD in Automation TestingBDD in Automation Testing
BDD in Automation Testing
 
Selenium basic
Selenium basicSelenium basic
Selenium basic
 
Selenium topic 1- Selenium Basic
Selenium topic 1-  Selenium BasicSelenium topic 1-  Selenium Basic
Selenium topic 1- Selenium Basic
 
Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016
 
Automated Tests in Agile based on Serenity BDD - Michał Szybalski
Automated Tests in Agile based on Serenity BDD - Michał SzybalskiAutomated Tests in Agile based on Serenity BDD - Michał Szybalski
Automated Tests in Agile based on Serenity BDD - Michał Szybalski
 
Ui BDD Testing
Ui BDD TestingUi BDD Testing
Ui BDD Testing
 
Selenium
SeleniumSelenium
Selenium
 
Serenity BDD - from executable specifications to living documentation
Serenity BDD - from executable specifications to living documentationSerenity BDD - from executable specifications to living documentation
Serenity BDD - from executable specifications to living documentation
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Behavior Driven Development - Live Webinar
Behavior Driven Development - Live WebinarBehavior Driven Development - Live Webinar
Behavior Driven Development - Live Webinar
 
Serenity-BDD training
Serenity-BDD trainingSerenity-BDD training
Serenity-BDD training
 
Selenium topic 3 -Web Driver Basics
Selenium topic 3 -Web Driver BasicsSelenium topic 3 -Web Driver Basics
Selenium topic 3 -Web Driver Basics
 
Basic Selenium Training
Basic Selenium TrainingBasic Selenium Training
Basic Selenium Training
 
Smarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automationSmarter ways to do selenium automation @ work, Selenium, automation
Smarter ways to do selenium automation @ work, Selenium, automation
 
Model-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next LevelModel-based Testing: Taking BDD/ATDD to the Next Level
Model-based Testing: Taking BDD/ATDD to the Next Level
 
BDD testing with cucumber
BDD testing with cucumberBDD testing with cucumber
BDD testing with cucumber
 
Behavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile TestingBehavior Driven Development (BDD) and Agile Testing
Behavior Driven Development (BDD) and Agile Testing
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and Selenium
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
 
[Thong Nguyen & Trong Bui] Behavior Driven Development (BDD) and Automation T...
[Thong Nguyen & Trong Bui] Behavior Driven Development (BDD) and Automation T...[Thong Nguyen & Trong Bui] Behavior Driven Development (BDD) and Automation T...
[Thong Nguyen & Trong Bui] Behavior Driven Development (BDD) and Automation T...
 

Similar a Bdd and-testing

Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkPeter Kofler
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Gianluca Padovani
 
Tdd pecha kucha_v2
Tdd pecha kucha_v2Tdd pecha kucha_v2
Tdd pecha kucha_v2Paul Boos
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With PytestEddy Reyes
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit testEugenio Lentini
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Gianluca Padovani
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityVictor Rentea
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017Xavi Hidalgo
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django ApplicationsHonza Král
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
Test Driven Development en Go con Ginkgo y Gomega
Test Driven Development en Go con Ginkgo y GomegaTest Driven Development en Go con Ginkgo y Gomega
Test Driven Development en Go con Ginkgo y GomegaSoftware Guru
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy CodeAndrea Polci
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionDionatan default
 

Similar a Bdd and-testing (20)

Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Tdd pecha kucha_v2
Tdd pecha kucha_v2Tdd pecha kucha_v2
Tdd pecha kucha_v2
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With Pytest
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Tdd in practice
Tdd in practiceTdd in practice
Tdd in practice
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of Purity
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
Python and test
Python and testPython and test
Python and test
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Test Driven Development en Go con Ginkgo y Gomega
Test Driven Development en Go con Ginkgo y GomegaTest Driven Development en Go con Ginkgo y Gomega
Test Driven Development en Go con Ginkgo y Gomega
 
Unit testing
Unit testingUnit testing
Unit testing
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 

Último

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Último (20)

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Bdd and-testing

  • 1. Behaviour Driven Development and thinking about testing Malcolm Tredinnick malcolm.tredinnick@gmail.com
  • 2. Why have I asked you here today? 1) Testing landscape 2) A different way to think about this 3) Code
  • 3. Chapter I: The Testing Landscape
  • 4. Isolated Integrated
  • 5. Isolated Integrated Testing unit External service size? availability Mocks Running time?
  • 6. Mocks ● Substitute for external systems & components ● Need to be injected into the tests ● “Monkey patching” ● Dependency injection
  • 7. Monkey patching import socket def setUp(...): socket.socket = DummySocketObject ...
  • 8. Mocks ● Substitute for external systems & components ● Need to be injected into the tests ● “Monkey patching” ● Dependency injection ● Need to be kept in synch with reality!
  • 9. Isolated Integrated Infrastructure
  • 10. ce n e na nt ai M Isolated Integrated Infrastructure
  • 11. Testing Strategies Some of many...
  • 12. Testing Strategies ● Formal verification
  • 13. Testing Strategies ● Formal verification ● Test everything you can think of
  • 14. Testing Strategies ● Formal verification ● Test everything you can think of ● Anti-regression suite No bug fix without a test
  • 15. Testing Strategies ● Formal verification ● Test everything you can think of ● Anti-regression suite ● Test driven development (TDD)
  • 16. TDD 1.Write a (failing) test for next method or class 2.Write minimal code to make test pass 3.Rinse, wash, repeat.
  • 17. Testing Strategies ● Formal verification ● Test everything you can think of ● Anti-regression suite ● Test driven development (TDD) “Specification, not verification”
  • 18. Testing Strategies ● Formal verification ● Test everything you can think of ● Anti-regression suite ● Test driven development (TDD) ● Documentation driven development (DDD?)
  • 19. Testing Strategies ● Formal verification ● Test everything you can think of ● Anti-regression suite ● Test driven development (TDD) ● Documentation driven development (DDD?) ● Behaviour driven development (BDD)
  • 20. Chapter II: A different way of thinking
  • 23. Interlude: Creating systems... Specification Implementation Testing
  • 24. Specification ● On (e-)paper? ● quick sketch ● formal requirements document ● mailing list discussion ● In your head?
  • 25. Specification ● Capturing the idea is probably good ● “What was I thinking smoking when...?”
  • 26. Specification As a [user or role], I want [feature] so that [something happens]
  • 27. Specification As a maze creator, I want to be able to specify dimensions so that a new maze of the given size is created.
  • 28. BDD What is the next most important thing the code should do?
  • 29. BDD What is the next most important thing the code should do? Be able to test this... ... then implement it.
  • 30. Scenario Given that [initial context], if and when [some event occurs] then [ensure some outcomes]
  • 31. Use case versus scenario As a [user or role], Given that [initial context], I want [feature] if and when [some event occurs] so that [something happens] then [ensure some outcomes]
  • 33. Interlude: Naming things Language helps guide our brain. Focuses the mind. Perhaps too exclusively.
  • 34. Interlude: Naming things The Sapir-Whorf Hypothesis: “[...] the structure of a language affects the ways in which its speakers are able to conceptualise their world [view].”
  • 35. Example #1: Python's unittest module
  • 36. Test titles class BasicFieldTests (TestCase): def test_field_name (self): ... def test_show_hidden_initial (self): ...
  • 37. Test titles class Fields (TestCase): def should_allow_name_override (self): ... class ChoiceFields (TestCase): def should_permit_initial_values_in_hidden_widgets (self): ...
  • 38. Run new test titles Write a load_test() method to pull out all the “should” methods. (Easy enough, but a few lines of code.)
  • 39. Matching to scenarios ● Typically, end up creating more classes than unittests (not a bad thing; classes are “free”). ● Thinking about test names helps with class names and roles. ● Context setup is done in setUp() method. ● Normal unittest assertions work fairly cleanly.
  • 41. Narrative style testing Jane created a new maze with a small (5 x 5) size. >>> from maze import Maze >>> maze = Maze(5, 5) Spot, her dog, did not think the new maze was the right size, but Jane was able to convince him like this: >>> maze.x_size 5 >>> maze.y_size 5 They found the entry and exit locations in their new maze: >>>maze.entry_cell (0, 0, “left”) (etc)
  • 42. Narrative style testing ● Excellent if you are truly writing a narrative. ● Can be difficult to maintain (but not always). ● Avoid if large amounts of setup required. ● Use with caution. Do use. Do not abuse.
  • 43. Example #3: Domain specific languages
  • 44. DSL packages ● Lettuce ● Freshen Both available through PyPI
  • 45. Freshen example Scenario: Divide regular numbers Given I have entered 3 into the calculator And I have entered 2 into the calculator When I press divide Then the result should be 1.5 on the screen (Code samples from Freshen documentation)
  • 46. Backing code from freshen import * import calculator @Before def before(unused): scc.calc = calculator.Calculator() scc.result = None @Given("I have entered (d+) into the calculator") def enter(num): scc.calc.push(int(num)) (Code samples from Freshen documentation)
  • 47. Backing code @When("I press (w+)") def press(button): op = getattr(scc.calc, button) scc.result = op() @Then("the result should be (.*) on the screen") def check_result(value): assert_equal(str(scc.result), value) (Code samples from Freshen documentation)
  • 48. Freshen templated example Scenario Outline: Add two numbers Given I have entered <input_1> into the calculator And I have entered <input_2> into the calculator When I press <button> Then the result should be <output> on the screen Examples: | input_1 | input_2 | button | output | | 20 | 30 | add | 50 | | 2 | 5 | add | 7 | | 0 | 40 | add | 40 | (Code samples from Freshen documentation)
  • 49. Conclusions(?) ● Behavioural tests are worth trying ● Question the way you think from time to time ● Are your tests' purpose clear to future you?
  • 50. https://github.com/malcolmt/bdd-and-testing-talk malcolm.tredinnick@gmail.com @malcolmt