SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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...
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 

Kürzlich hochgeladen (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

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