SlideShare una empresa de Scribd logo
1 de 45
Descargar para leer sin conexión
https://www.linkedin.com/in/umaghotikar/
https://twitter.com/umaghotikar
Agenda
• Unit Testing – What, Why?
• Guidelines
• TDD and BDD
• Story Framework
• TestBox
• Given – When – Then syntax
• General structure for writing Unit Tests
• Mocking – What? Why?
• MockBox
• Demo examples
• Resources
• Unit Testing is a level of software testing where individual units/ components
of a software are tested
• A unit is a smallest piece of functionality that can be tested in isolation
• Unit tests are low-level, small scope and fast
What is Unit Testing?
Why?
• To validate that each unit of the software performs
as designed
• Development and refactoring is faster
• Increases confidence in changing/ maintaining code
• Provides instant feedback
• Modular code becomes more reusable
• Can expose high coupling
• Less cost of fixing a defect
• Debugging is easy - Easy to locate the bug
• Acts as a safety net
• Better quality code and more stable code
Unit tests must be
• Fast
• Isolated
• Independent
• Robust
• Maintainable
• Purposeful
• Automated
• Name tests properly
Guidelines for writing good unit tests
Unit tests should be
• Fast
• Isolated
• Independent
• Robust
• Maintainable
• Purposeful
Code should be
• Keep the units small
• High cohesion and low coupling
TDD – Test Driven Development
Test Driven Development
mantra:
“red/green/refactor”
• red means fail
• green means pass
• and then we refactor, if
any
TDD – Example `concatenate()`: Test
TDD – Example `concatenate()`: Code
TDD – Example `concatenate()`: Test Result
TDD – Test Driven Development
• TDD is a technique for building software that guides software development by
writing tests – so we write the tests first and then we write the code
• It was developed / rediscovered by Kent Beck in the late 1990's as part of Extreme
Programming
• Focuses on CFCs and methods
TDD – Test Driven Development
TDD helps to
• Get immediate feedback
• Create tests before rather than after
• Create some documentation
• Verify that the source code compiles and executes
• Assist in assuring that the code should be as unit testable as possible
What TDD doesn’t do / Limitations of TDD?
• Very much developer oriented
• Tedious as we always have to test methods
• Refactoring is a pain
• It is not about verifying software requirements – since it only focuses on functions and
verifies that functions are working correctly
• Neither verifies stakeholders' expectations nor expresses that requirements are satisfied
Questions:
• Where to start?
• What to test?
• What not to test?
BDD – Behavior Driven Development
• Dan North: https://dannorth.net/introducing-bdd/
• BDD is a software development process that emerged from TDD. It is an evolution of TDD
and has roots in TDD
• Ubiquitous Language: BDD is largely facilitated through the use of a simple domain
specific language using natural language constructs (e.g., English-like sentences) that can
express the behavior and the expected outcomes
• Focuses on stories or requirements rather than on functions
• BDD focuses on what a system should do and not on how it should be implemented
• Better readability
• Verifies that software works but also that it meets customer expectations
BDD – Behavior Driven Development
Story Framework
• Story: We will start with a story
• Scenario: We will create scenarios from it
• Specification: We will then code our specifications
Story Framework
Story template:
As a [role]
I want [feature]
So that [benefit]
Scenarios:
Given [context]
And [some more context]
When [event]
Then [outcome]
And [another outcome]
Stories to Scenarios
As an application user
I want to have publish file functionality
So that file gets published
File gets successfully copied from source (unpublished folder) to destination
(published folder) and we delete the file at the source path
Given: I have source path
AND destination path
AND file to be copied
When: I click the publish button
Then: File is copied from source to destination
AND file at source is compared with the file at destination
AND file at source is deleted
Story
Scenario
Scenarios to Specification in TestBox
describe("file gets successfully copied from source to destination and we delete the file at source path", function(){
given("source path, destination path and file to be copied", function() {
when("I click the publish button", function() {
then("file should be copied from source to destination", function() {
//some code and expect statement
});
then("file at source should be compared with the file at destination", function() {
//some code and expect statement
});
then("file at source should be deleted", function() {
//some code and expect statement
});
});
});
});
What is TestBox?
• TestBox is a next generation testing framework for
ColdFusion (CFML)
• It is based on BDD for providing a clean obvious
syntax for writing tests
• With TestBox, we are bringing in the Syntax for BDD
into our unit testing
• It supports xUnit style of testing and MXUnit
compatibilities
• It contains not only a testing framework, runner,
assertions and expectations library but also ships
with MockBox
BDD - Life Cycle Methods, Suites, Tests and Specs
BDD - Life Cycle Methods, Suites, Tests and Specs
BDD – Example `concatenate()`: Test
BDD – Example `concatenate()`: Test Result
Given – When – Then
• `given`: is the state of the world before
you begin the behavior you are
specifying in this scenario. You can think
of it as the pre-conditions to the test.
• `when`: is the behavior that you are
specifying / event trigger
• `then`: is the changes you expect due to
the specified behavior / postcondition
which must be verified as the outcome
of the action that follows the trigger
The essential idea is to break down writing a
scenario (or test) into three sections:
Structure for writing Unit Tests
Four Phase Test
• Setup (Given)
• Exercise (When)
• Verify (Then)
• Teardown (Clean up)
Arrange – Act – Assert
• Most unit tests don’t need teardown. Unit tests (for the bulk of the system) don’t
talk to external systems, databases, files, etc., and Arrange-Act-Assert is a pattern
for unit tests.
Examples
• Functions with no dependencies / interactions
• Functions with dependencies / interactions
Functions with no dependencies / interactions
• Isolated and independent functions
• Simple to unit test
• Examples:
• concatenate()
• division() – Expecting Exceptions: Make
sure to exercise all code paths
BDD – Example `division()`: Test
BDD – Example `division()`: Code
BDD – Example `division()`: Test Result
Functions with dependencies / interactions
Functions with dependencies / interactions
https://martinfowler.com/bliki/UnitTest.html
https://leanpub.com/wewut
Styles of testing
• Classic: Prefers sociable
tests
• Mockist: Insists upon
solitary tests
Mocking
• Mocking is creating objects that simulate the behavior of real objects
• A mock is a test double that stands in for real implementation code during the unit
testing process
Why to Mock? What can we mock?
Why?
• To isolate the behavior of the SUT
• To be able to develop when the collaborators are not yet built / unavailable
• To be able to control data and expectations
• When collaborator’s behavior is hard to control / impractical to incorporate into
the unit test
What?
• Methods, Components, Properties, API calls, data, filesystems, etc
What is MockBox?
• Mocking Framework
• It is a companion package to TestBox
• It gives us advanced mocking/stubbing
capabilities
• It gives us ability to create mock objects
• It has mocking methods and verification
methods available
Mocking – Example: Interaction with File Systems
Code Demo
How to mock a Query?
How to mock a Query?
Interaction with External APIs – Google Geocoding API
https://developers.google.com/maps/documentation/geocoding/intro
• Address: 1600 Amphitheatre Pkwy, Mountain View, CA 94043
Scenario: Location pins are to be plotted on the Google map using Google Geocoding API
Given: A good / valid address
When: `demoMap()` function is called
Then: the good geocode is returned and location pin is plotted on
the Google Map
Interaction with External APIs – Code
Interaction with External APIs – Mock Example
Resources
• https://testbox.ortusbooks.com/
• https://en.wikipedia.org/wiki/Unit_testing
• https://en.wikipedia.org/wiki/Test-driven_development
• https://martinfowler.com/bliki/UnitTest.html
• https://martinfowler.com/bliki/TestDrivenDevelopment.html
• http://blog.acntech.no/unit-testing-myths-and-
misconceptions/
• https://en.wikipedia.org/wiki/Behavior-driven_development
• https://dannorth.net/introducing-bdd/
• https://dannorth.net/whats-in-a-story/
• https://martinfowler.com/bliki/GivenWhenThen.html
• http://xunitpatterns.com/Four%20Phase%20Test.html
• http://xp123.com/articles/3a-arrange-act-assert/
• https://martinfowler.com/articles/mocksArentStubs.html
• https://stackoverflow.com/questions/346372/whats-the-
difference-between-faking-mocking-and-stubbing
• https://github.com/gratzc/mock-it-
baby/blob/master/Mock%20It%20Baby.pdf
• https://medium.com/javascript-scene/mocking-is-a-code-
smell-944a70c90a6a
• https://en.wikipedia.org/wiki/XUnit
• http://blog.adamcameron.me/2013/10/unit-testing-why-
you-shouldnt-bother.html
• https://www.ortussolutions.com/blog/testbox-bdd-video-
slides-at-nvcfug
• https://leanpub.com/wewut
Final Thoughts
https://www.linkedin.com/in/umaghotikar/
https://twitter.com/umaghotikar

Más contenido relacionado

La actualidad más candente

Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...SQALab
 
Testing - How Vital and How Easy to use
Testing - How Vital and How Easy to useTesting - How Vital and How Easy to use
Testing - How Vital and How Easy to useUma Ghotikar
 
Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016Steven Smith
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?Steven Mak
 
May: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and ChallengesMay: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and ChallengesTriTAUG
 
Power-Up Your Test Suite with OLE Automation by Joshua Russell
Power-Up Your Test Suite with OLE Automation by Joshua RussellPower-Up Your Test Suite with OLE Automation by Joshua Russell
Power-Up Your Test Suite with OLE Automation by Joshua RussellQA or the Highway
 
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016Steven Smith
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingSteven Smith
 
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald BelchamGetting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham.NET Conf UY
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing SoftwareSteven Smith
 
Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD DemonstratedAlan Christensen
 
Continuous Integration: Finding problems soonest
Continuous Integration: Finding problems soonestContinuous Integration: Finding problems soonest
Continuous Integration: Finding problems soonestShawn Jones
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
Automated Acceptance Tests in .NET
Automated Acceptance Tests in .NETAutomated Acceptance Tests in .NET
Automated Acceptance Tests in .NETWyn B. Van Devanter
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for seleniumapoorvams
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeExcella
 
Unit testing presentation
Unit testing presentationUnit testing presentation
Unit testing presentationArthur Freyman
 

La actualidad más candente (19)

Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...
 
Testing - How Vital and How Easy to use
Testing - How Vital and How Easy to useTesting - How Vital and How Easy to use
Testing - How Vital and How Easy to use
 
Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016Improving the Quality of Existing Software - DevIntersection April 2016
Improving the Quality of Existing Software - DevIntersection April 2016
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?
 
Skillwise Unit Testing
Skillwise Unit TestingSkillwise Unit Testing
Skillwise Unit Testing
 
May: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and ChallengesMay: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and Challenges
 
Power-Up Your Test Suite with OLE Automation by Joshua Russell
Power-Up Your Test Suite with OLE Automation by Joshua RussellPower-Up Your Test Suite with OLE Automation by Joshua Russell
Power-Up Your Test Suite with OLE Automation by Joshua Russell
 
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald BelchamGetting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD Demonstrated
 
Continuous Integration: Finding problems soonest
Continuous Integration: Finding problems soonestContinuous Integration: Finding problems soonest
Continuous Integration: Finding problems soonest
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Automated Acceptance Tests in .NET
Automated Acceptance Tests in .NETAutomated Acceptance Tests in .NET
Automated Acceptance Tests in .NET
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Unit testing presentation
Unit testing presentationUnit testing presentation
Unit testing presentation
 

Similar a Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into the Box 2018

Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven DevelopmentSarah Dutkiewicz
 
Test Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveTest Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveMalinda Kapuruge
 
Introduction to Testing and TDD
Introduction to Testing and TDDIntroduction to Testing and TDD
Introduction to Testing and TDDSarah Dutkiewicz
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Malinda Kapuruge
 
Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersSPC Adriatics
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)Nacho Cougil
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven developmentEinar Ingebrigtsen
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testingDuy Tan Geek
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspecjeffrey1ross
 
Automated testing in javascript
Automated testing in javascriptAutomated testing in javascript
Automated testing in javascriptMichael Yagudaev
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)ssusercaf6c1
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)Nacho Cougil
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingSahar Nofal
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile DeveloperBSGAfrica
 
Practical unit testing in c & c++
Practical unit testing in c & c++Practical unit testing in c & c++
Practical unit testing in c & c++Matt Hargett
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Codecamp Romania
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)Peter Kofler
 

Similar a Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into the Box 2018 (20)

Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven Development
 
Test Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveTest Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s Perspective
 
Introduction to Testing and TDD
Introduction to Testing and TDDIntroduction to Testing and TDD
Introduction to Testing and TDD
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
 
Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill Ayers
 
Test box bdd
Test box bddTest box bdd
Test box bdd
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)
 
Driving application development through behavior driven development
Driving application development through behavior driven developmentDriving application development through behavior driven development
Driving application development through behavior driven development
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Beginners overview of automated testing with Rspec
Beginners overview of automated testing with RspecBeginners overview of automated testing with Rspec
Beginners overview of automated testing with Rspec
 
Automated testing in javascript
Automated testing in javascriptAutomated testing in javascript
Automated testing in javascript
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile Developer
 
Practical unit testing in c & c++
Practical unit testing in c & c++Practical unit testing in c & c++
Practical unit testing in c & c++
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 

Más de Ortus Solutions, Corp

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Secure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionSecure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionOrtus Solutions, Corp
 
Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Ortus Solutions, Corp
 
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfOrtus Solutions, Corp
 
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfOrtus Solutions, Corp
 
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfOrtus Solutions, Corp
 
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfOrtus Solutions, Corp
 
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfOrtus Solutions, Corp
 
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfOrtus Solutions, Corp
 
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfOrtus Solutions, Corp
 
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfOrtus Solutions, Corp
 
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfOrtus Solutions, Corp
 
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfOrtus Solutions, Corp
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfOrtus Solutions, Corp
 
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfOrtus Solutions, Corp
 
ITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfOrtus Solutions, Corp
 

Más de Ortus Solutions, Corp (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Ortus Government.pdf
Ortus Government.pdfOrtus Government.pdf
Ortus Government.pdf
 
Luis Majano The Battlefield ORM
Luis Majano The Battlefield ORMLuis Majano The Battlefield ORM
Luis Majano The Battlefield ORM
 
Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI
 
Secure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusionSecure your Secrets and Settings in ColdFusion
Secure your Secrets and Settings in ColdFusion
 
Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023
 
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdfITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
ITB_2023_Human-Friendly_Scheduled_Tasks_Giancarlo_Gomez.pdf
 
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdfITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
ITB_2023_CommandBox_Multi-Server_-_Brad_Wood.pdf
 
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdfITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
ITB_2023_The_Many_Layers_of_OAuth_Keith_Casey_.pdf
 
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdfITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
ITB_2023_Relationships_are_Hard_Data_modeling_with_NoSQL_Curt_Gratz.pdf
 
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdfITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
ITB_2023_Extend_your_contentbox_apps_with_custom_modules_Javier_Quintero.pdf
 
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdfITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
ITB_2023_25_Most_Dangerous_Software_Weaknesses_Pete_Freitag.pdf
 
ITB_2023_CBWire_v3_Grant_Copley.pdf
ITB_2023_CBWire_v3_Grant_Copley.pdfITB_2023_CBWire_v3_Grant_Copley.pdf
ITB_2023_CBWire_v3_Grant_Copley.pdf
 
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdfITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
ITB_2023_Practical_AI_with_OpenAI_-_Grant_Copley_.pdf
 
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdfITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
ITB_2023_When_Your_Applications_Work_As_a_Team_Nathaniel_Francis.pdf
 
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdfITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
ITB_2023_Faster_Apps_That_Wont_Get_Crushed_Brian_Klaas.pdf
 
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdfITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
ITB_2023_Chatgpt_Box_Scott_Steinbeck.pdf
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdfITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
 
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdfITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
ITB_2023_Create_as_many_web_sites_or_web_apps_as_you_want_George_Murphy.pdf
 
ITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdfITB2023 Developing for Performance - Denard Springle.pdf
ITB2023 Developing for Performance - Denard Springle.pdf
 

Último

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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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 PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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
 
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
 

Último (20)

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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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 PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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
 
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
 

Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into the Box 2018

  • 1.
  • 3. Agenda • Unit Testing – What, Why? • Guidelines • TDD and BDD • Story Framework • TestBox • Given – When – Then syntax • General structure for writing Unit Tests • Mocking – What? Why? • MockBox • Demo examples • Resources
  • 4. • Unit Testing is a level of software testing where individual units/ components of a software are tested • A unit is a smallest piece of functionality that can be tested in isolation • Unit tests are low-level, small scope and fast What is Unit Testing?
  • 5. Why? • To validate that each unit of the software performs as designed • Development and refactoring is faster • Increases confidence in changing/ maintaining code • Provides instant feedback • Modular code becomes more reusable • Can expose high coupling • Less cost of fixing a defect • Debugging is easy - Easy to locate the bug • Acts as a safety net • Better quality code and more stable code
  • 6. Unit tests must be • Fast • Isolated • Independent • Robust • Maintainable • Purposeful • Automated • Name tests properly Guidelines for writing good unit tests Unit tests should be • Fast • Isolated • Independent • Robust • Maintainable • Purposeful Code should be • Keep the units small • High cohesion and low coupling
  • 7. TDD – Test Driven Development Test Driven Development mantra: “red/green/refactor” • red means fail • green means pass • and then we refactor, if any
  • 8. TDD – Example `concatenate()`: Test
  • 9. TDD – Example `concatenate()`: Code
  • 10. TDD – Example `concatenate()`: Test Result
  • 11. TDD – Test Driven Development • TDD is a technique for building software that guides software development by writing tests – so we write the tests first and then we write the code • It was developed / rediscovered by Kent Beck in the late 1990's as part of Extreme Programming • Focuses on CFCs and methods
  • 12. TDD – Test Driven Development TDD helps to • Get immediate feedback • Create tests before rather than after • Create some documentation • Verify that the source code compiles and executes • Assist in assuring that the code should be as unit testable as possible
  • 13. What TDD doesn’t do / Limitations of TDD? • Very much developer oriented • Tedious as we always have to test methods • Refactoring is a pain • It is not about verifying software requirements – since it only focuses on functions and verifies that functions are working correctly • Neither verifies stakeholders' expectations nor expresses that requirements are satisfied Questions: • Where to start? • What to test? • What not to test?
  • 14. BDD – Behavior Driven Development • Dan North: https://dannorth.net/introducing-bdd/ • BDD is a software development process that emerged from TDD. It is an evolution of TDD and has roots in TDD • Ubiquitous Language: BDD is largely facilitated through the use of a simple domain specific language using natural language constructs (e.g., English-like sentences) that can express the behavior and the expected outcomes • Focuses on stories or requirements rather than on functions • BDD focuses on what a system should do and not on how it should be implemented • Better readability • Verifies that software works but also that it meets customer expectations
  • 15. BDD – Behavior Driven Development
  • 16. Story Framework • Story: We will start with a story • Scenario: We will create scenarios from it • Specification: We will then code our specifications
  • 17. Story Framework Story template: As a [role] I want [feature] So that [benefit] Scenarios: Given [context] And [some more context] When [event] Then [outcome] And [another outcome]
  • 18. Stories to Scenarios As an application user I want to have publish file functionality So that file gets published File gets successfully copied from source (unpublished folder) to destination (published folder) and we delete the file at the source path Given: I have source path AND destination path AND file to be copied When: I click the publish button Then: File is copied from source to destination AND file at source is compared with the file at destination AND file at source is deleted Story Scenario
  • 19. Scenarios to Specification in TestBox describe("file gets successfully copied from source to destination and we delete the file at source path", function(){ given("source path, destination path and file to be copied", function() { when("I click the publish button", function() { then("file should be copied from source to destination", function() { //some code and expect statement }); then("file at source should be compared with the file at destination", function() { //some code and expect statement }); then("file at source should be deleted", function() { //some code and expect statement }); }); }); });
  • 20. What is TestBox? • TestBox is a next generation testing framework for ColdFusion (CFML) • It is based on BDD for providing a clean obvious syntax for writing tests • With TestBox, we are bringing in the Syntax for BDD into our unit testing • It supports xUnit style of testing and MXUnit compatibilities • It contains not only a testing framework, runner, assertions and expectations library but also ships with MockBox
  • 21. BDD - Life Cycle Methods, Suites, Tests and Specs
  • 22. BDD - Life Cycle Methods, Suites, Tests and Specs
  • 23. BDD – Example `concatenate()`: Test
  • 24. BDD – Example `concatenate()`: Test Result
  • 25. Given – When – Then • `given`: is the state of the world before you begin the behavior you are specifying in this scenario. You can think of it as the pre-conditions to the test. • `when`: is the behavior that you are specifying / event trigger • `then`: is the changes you expect due to the specified behavior / postcondition which must be verified as the outcome of the action that follows the trigger The essential idea is to break down writing a scenario (or test) into three sections:
  • 26. Structure for writing Unit Tests Four Phase Test • Setup (Given) • Exercise (When) • Verify (Then) • Teardown (Clean up) Arrange – Act – Assert • Most unit tests don’t need teardown. Unit tests (for the bulk of the system) don’t talk to external systems, databases, files, etc., and Arrange-Act-Assert is a pattern for unit tests.
  • 27. Examples • Functions with no dependencies / interactions • Functions with dependencies / interactions
  • 28. Functions with no dependencies / interactions • Isolated and independent functions • Simple to unit test • Examples: • concatenate() • division() – Expecting Exceptions: Make sure to exercise all code paths
  • 29. BDD – Example `division()`: Test
  • 30. BDD – Example `division()`: Code
  • 31. BDD – Example `division()`: Test Result
  • 32. Functions with dependencies / interactions
  • 33. Functions with dependencies / interactions https://martinfowler.com/bliki/UnitTest.html https://leanpub.com/wewut Styles of testing • Classic: Prefers sociable tests • Mockist: Insists upon solitary tests
  • 34. Mocking • Mocking is creating objects that simulate the behavior of real objects • A mock is a test double that stands in for real implementation code during the unit testing process
  • 35. Why to Mock? What can we mock? Why? • To isolate the behavior of the SUT • To be able to develop when the collaborators are not yet built / unavailable • To be able to control data and expectations • When collaborator’s behavior is hard to control / impractical to incorporate into the unit test What? • Methods, Components, Properties, API calls, data, filesystems, etc
  • 36. What is MockBox? • Mocking Framework • It is a companion package to TestBox • It gives us advanced mocking/stubbing capabilities • It gives us ability to create mock objects • It has mocking methods and verification methods available
  • 37. Mocking – Example: Interaction with File Systems Code Demo
  • 38. How to mock a Query?
  • 39. How to mock a Query?
  • 40. Interaction with External APIs – Google Geocoding API https://developers.google.com/maps/documentation/geocoding/intro • Address: 1600 Amphitheatre Pkwy, Mountain View, CA 94043 Scenario: Location pins are to be plotted on the Google map using Google Geocoding API Given: A good / valid address When: `demoMap()` function is called Then: the good geocode is returned and location pin is plotted on the Google Map
  • 41. Interaction with External APIs – Code
  • 42. Interaction with External APIs – Mock Example
  • 43. Resources • https://testbox.ortusbooks.com/ • https://en.wikipedia.org/wiki/Unit_testing • https://en.wikipedia.org/wiki/Test-driven_development • https://martinfowler.com/bliki/UnitTest.html • https://martinfowler.com/bliki/TestDrivenDevelopment.html • http://blog.acntech.no/unit-testing-myths-and- misconceptions/ • https://en.wikipedia.org/wiki/Behavior-driven_development • https://dannorth.net/introducing-bdd/ • https://dannorth.net/whats-in-a-story/ • https://martinfowler.com/bliki/GivenWhenThen.html • http://xunitpatterns.com/Four%20Phase%20Test.html • http://xp123.com/articles/3a-arrange-act-assert/ • https://martinfowler.com/articles/mocksArentStubs.html • https://stackoverflow.com/questions/346372/whats-the- difference-between-faking-mocking-and-stubbing • https://github.com/gratzc/mock-it- baby/blob/master/Mock%20It%20Baby.pdf • https://medium.com/javascript-scene/mocking-is-a-code- smell-944a70c90a6a • https://en.wikipedia.org/wiki/XUnit • http://blog.adamcameron.me/2013/10/unit-testing-why- you-shouldnt-bother.html • https://www.ortussolutions.com/blog/testbox-bdd-video- slides-at-nvcfug • https://leanpub.com/wewut