SlideShare a Scribd company logo
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

More Related Content

What's hot

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 use
Uma 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 2016
Steven Smith
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven 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
 
Skillwise Unit Testing
Skillwise Unit TestingSkillwise Unit Testing
Skillwise Unit Testing
Skillwise Group
 
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
TriTAUG
 
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
QA 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 2016
Steven Smith
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
Steven 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 Software
Steven Smith
 
Practical TDD Demonstrated
Practical TDD DemonstratedPractical TDD Demonstrated
Practical TDD Demonstrated
Alan Christensen
 
Continuous Integration: Finding problems soonest
Continuous Integration: Finding problems soonestContinuous Integration: Finding problems soonest
Continuous Integration: Finding problems soonest
Shawn 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 .NET
Wyn B. Van Devanter
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
apoorvams
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
Excella
 
Unit testing presentation
Unit testing presentationUnit testing presentation
Unit testing presentation
Arthur Freyman
 

What's hot (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 to 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 Development
Sarah 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 Perspective
Malinda Kapuruge
 
Introduction to Testing and TDD
Introduction to Testing and TDDIntroduction to Testing and TDD
Introduction to Testing and TDD
Sarah 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 Ayers
SPC Adriatics
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
Ganesh 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
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sergey Aganezov
 
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
jeffrey1ross
 
Automated testing in javascript
Automated testing in javascriptAutomated testing in javascript
Automated testing in javascript
Michael 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 Testing
Sahar 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 Developer
BSGAfrica
 
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 to 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)
 

More from Ortus Solutions, Corp

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
ITB2024 - Keynote Day 1 - Ortus Solutions.pdf
ITB2024 - Keynote Day 1 - Ortus Solutions.pdfITB2024 - Keynote Day 1 - Ortus Solutions.pdf
ITB2024 - Keynote Day 1 - Ortus Solutions.pdf
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 DATABASE
Ortus Solutions, Corp
 
Ortus Government.pdf
Ortus Government.pdfOrtus Government.pdf
Ortus Government.pdf
Ortus Solutions, Corp
 
Luis Majano The Battlefield ORM
Luis Majano The Battlefield ORMLuis Majano The Battlefield ORM
Luis Majano The Battlefield ORM
Ortus Solutions, Corp
 
Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI Brad Wood - CommandBox CLI
Brad Wood - CommandBox CLI
Ortus 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 ColdFusion
Ortus Solutions, Corp
 
Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023Daniel Garcia ContentBox: CFSummit 2023
Daniel Garcia ContentBox: CFSummit 2023
Ortus 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.pdf
Ortus 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.pdf
Ortus 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_.pdf
Ortus 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.pdf
Ortus 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.pdf
Ortus 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.pdf
Ortus Solutions, Corp
 
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
Ortus 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_.pdf
Ortus 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.pdf
Ortus 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.pdf
Ortus 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.pdf
Ortus Solutions, Corp
 

More from Ortus Solutions, Corp (20)

BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
ITB2024 - Keynote Day 1 - Ortus Solutions.pdf
ITB2024 - Keynote Day 1 - Ortus Solutions.pdfITB2024 - Keynote Day 1 - Ortus Solutions.pdf
ITB2024 - Keynote Day 1 - Ortus Solutions.pdf
 
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
 

Recently uploaded

How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 

Recently uploaded (20)

How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 

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