SlideShare a Scribd company logo
http://www.depthconsulting.ca
http://www.depthconsulting.ca
Developer
Fundamentals
:
The Series
Calgary
.NET User
Group
Unit Testing
A Brief Explanation
Dave White
Microsoft MVP – Visual Studio ALM
http://www.depthconsulting.ca
Developer Fundamentals Series
Testing – Nov. 26, 2014
SOLID – February
Dependency Injection – April
Source Control – Branching/Merging – June
Putting It All Together – July
http://www.depthconsulting.ca
Dave White
Principal Consultant – Depth Consulting
http://linkd.in/giMxuw
@AgileRamblings
• In IT for over 15 years
• Microsoft MVP – Visual Studio ALM
• Kanban/Agile Evangelist, Speaker
• PRDC 2011, 2012, LKUK, Local events
• Program Director – KCP Program - LKU
• Professional Scrum Master
• Microsoft Platform Developer (C#, Web, WPF)
http://www.agileramblings.com
http://www.depthconsulting.ca
Simon Timms
Senior .NET Dev – Pacesetter Directional Drilling
http://linkd.in/15pYAWL
@stimms
• In IT for over a decade (+/− few months)
• Microsoft MVP – ASP.NET/IIS
• Prolific Speaker and Community Involvement
• PRDC (many), AzureCamp, Local events
• Calgary .NET User Group – President
• Author
• Loves Development
• Polyglot
• Web apps, .NET back ends
• Visualization and Cloud
http://blog.simontimms.com/about/
http://www.depthconsulting.ca
WHY?
http://www.depthconsulting.ca
Why We Don’t Test
• No one around me is
doing it
• Too hard to learn
• No tools
• My stuff doesn’t
need it
• Bugs aren’t my
problem
• Our code is horrible
• No time
• Manager won’t let
me (cost or time)
• Maintain my tests
now too?!?!
• We have QA people
http://www.depthconsulting.ca
The truth of the matter…
• Everyone is doing it
• Easier than ever
• Investment in tools
• Private and OSS
• Increasing
Complexity
• Business and technical
• Late discovery of
defects is expensive
• You can start small
• QA demand growing
• You will be a better
developer
• Drives growth down
maturity path
• It makes you faster
• Less time on bugs
• More time on fun
http://www.depthconsulting.ca
I got
this!
By Adam Jones Adam63 (Own work) [CC-BY-SA-3.0
(http://creativecommons.org/licenses/by-sa/3.0)],
via Wikimedia Commons
http://www.depthconsulting.ca
Types of Tests
Unit Test (TDD, BDD or Test After)
One class, One Method, One Scenario per
Test
Not Unit Test
Integration Test
Multiple classes/methods
Feature Test
Multiple classes/method/scenarios
Database Tests
Single class/method – multiple
boundaries
UI Tests (Automated or manual)
Functional test of application
Load Testing
My system sure can carry the load!
Performance Testing
My unit is very performant.
Usability Testing
http://www.depthconsulting.ca
Unit Test Sub-Types
Behaviour
• Concerned with
interactions between
dependent objects
• Did Object A user
Object B correctly
• Requires mocking
framework
State
• Concerned only with
object mechanics
• Typically faking data
in stubs (don’t need
mocking framework)
http://www.depthconsulting.ca
Anatomy of a Test
[TestClass] (or Fixture)
Used to identify classes that contain test
methods
[TestInitialize] (or Setup)
Identifies the method to run before the
test to allocate and configure resources
needed by all of the tests
[TestMethod] (Test, Fact, or
Theory)
Used to identify test methods
[TestCleanup] (or Teardown)
Identifies the method to run after the
tests to free resources allocated during
the test run
[Ignor
e]
sut or cut = subject or class under test
http://www.depthconsulting.ca
Basic Layout
TestClass
public class
TestMethod
public void
// arrange
// act
// assert
http://www.depthconsulting.ca
Unit Test Frameworks
http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
http://www.depthconsulting.ca
Demo
http://www.depthconsulting.ca
By Crosa (Flickr: Scream) [CC-BY-2.0
(http://creativecommons.org/licenses/by/2.0)],
via Wikimedia Commons
YOU
CAN’T
MAKE
ME
TEST
FIRST!!
http://www.depthconsulting.ca
Pivot – Test Driven Development
• TDD is mostly a change in perspective
• NOT ABOUT TESTING
• A wonderful side effect
• Unit Tests intend to characterize or “pin down” behavior
• TDD intend to design classes
• First create a hypothesis about your class
• Create your class aligned with hypothesis
• Run experiment
• Rinse & Repeat
http://www.depthconsulting.ca
Demo
http://www.depthconsulting.ca
By FelipeIbazeta (Own work) [CC-BY-SA-3.0
(http://creativecommons.org/licenses/by-sa/3.0)],
via Wikimedia Commons
HUH?!?
My tests
should
be about
business?
http://www.depthconsulting.ca
Pivot – Behaviour Driven
Development• BDD is mostly about describing things
different
• TestClass Per Scenario
• NOT ABOUT TESTING
• A wonderful side effect
• Create a business language scenario
• Setup the world to model your situation
• Run the scenario
• Probably multiple assertions in a TestClass
http://www.depthconsulting.ca
Just tilt your head…
http://www.depthconsulting.ca
These are not the
demos your looking
for…
http://www.depthconsulting.ca
QA Pros
are
people
too!
(This guys last name is
really Tester!)
By U.S. Government (http://tester.senate.gov/)
[Public domain],
via Wikimedia Commons
http://www.depthconsulting.ca
Pivot – There is No Unit in UI
• UI Testing is still good!
• Just not a unit test
• Automated or Manual
• Design your tests - Describe them in
Test Cases
• Execute them
• Automate them
• <INSERT DEVELOPER HERE>
• Maintain them
• <INSERT MORE DEVELOPER HERE>
http://www.depthconsulting.ca
Microsoft Developers UI Testing
• Coded UI Testing
http://msdn.microsoft.com/en-us/library/dd286726.aspx
• Selenium
http://www.seleniumhq.org/
• WatiN
http://watin.org/
http://www.depthconsulting.ca
Hold
on a
second
here
Mister! By Achim Hering (Own work)
[GFDL (http://www.gnu.org/copyleft/fdl.html) or
CC-BY-3.0 (http://creativecommons.org/licenses/by/3.0)]
via Wikimedia Commons
http://www.depthconsulting.ca
The Real Truth - It Can’t Be All
Roses• Testing is hard
• Only because it is:
• Unfamiliar – we don’t have these skills yet
• Burdened by a MOUNTAIN of technical debt and bad design
• You will be slower at first
• It may force you to learn new things
• SOLID, DI, new Tooling
• These are all GOOD things!
• Managers may be suspicious
• You have to go slow… Start small!
http://www.depthconsulting.ca
The Real Truth – There ARE Roses
• You will get faster
• You will create higher quality product
• You will create better designs
• You will help your QA Professional
teammates
• You don’t have to ask permission
• Most of the tools are free or inexpensive
• You might already have them!!
• You will (eventually) have more fun! :D
http://www.depthconsulting.ca
We can
do this!
By Wonderlane from Seattle, USA [CC-BY-2.0
(http://creativecommons.org/licenses/by/2.0)],
via Wikimedia Commons
http://www.depthconsulting.ca
Next Steps
• Just go do it
• Do not give up
• Do not ask
permission
• Do not give up
• Start small
• Do not give up
• Ask for help
• Do not give up
KEEP
CALM
and
TEST
ON
http://www.depthconsulting.ca
Tools
• Visual Studio Community
http://www.visualstudio.com/products/visual-studio-community-vs
• Visual Studio 2015 Preview
http://www.visualstudio.com/en-us/news/vs2015-preview-vs
• Nuget
• Nunit, xUnit
• http://www.nunit.org
• http://github.com/xunit/xunit
http://www.depthconsulting.ca
I’ve Skipped a LOT
• Mocking
• Refactoring
• SOLID
• Dependency Injecting
• Automation
• Code Coverage
http://www.depthconsulting.ca
These are the MeetUps you’re
looking for…
Testing – Nov. 26, 2014
SOLID – February
Dependency Injection – April
Source Control – Branching/Merging – June
Putting It All Together – July
http://www.depthconsulting.ca
NOW PRIZES!!
2 ReSharper licences to the loudest Unit
Testers in the room!!
https://www.jetbrains.com/resharper/
http://www.depthconsulting.ca
Thanks
Dave White
@agileramblings
http://www.agileramblings.co
m
dave@depthconsulting.ca
Simon Timms
@stimms
http://blog.simontimms.com
stimms@gmail.com

More Related Content

PDF
Better Page Object Handling with Loadable Component Pattern
PDF
Mastering Test Automation: How to Use Selenium Successfully
PDF
[Webinar] Continuous Testing Done Right: Test Automation at the World's Leadi...
PDF
Getting Started with Selenium
PPTX
Qa process
PDF
Rspec and Capybara Intro Tutorial at RailsConf 2013
PDF
Getting By Without "QA"
PPTX
Brace yourself from automation death trap
Better Page Object Handling with Loadable Component Pattern
Mastering Test Automation: How to Use Selenium Successfully
[Webinar] Continuous Testing Done Right: Test Automation at the World's Leadi...
Getting Started with Selenium
Qa process
Rspec and Capybara Intro Tutorial at RailsConf 2013
Getting By Without "QA"
Brace yourself from automation death trap

What's hot (20)

PDF
How To Use Selenium Successfully
PPT
Behavior Driven Development (BDD) and Agile Testing
PDF
How To Use Selenium Successfully
PPTX
Automated Acceptance Tests in .NET
PDF
Behavior Driven Development and Automation Testing Using Cucumber
PPT
Selenium course training institute ameerpet hyderabad – Best software trainin...
PPTX
Jbehave selenium
PDF
Continuous Testing Meets the Classroom at Code.org
PDF
Perils of Page-Object Pattern
PDF
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
PPTX
Introduction to SoapUI day 1
PDF
Sharing the pain using Protractor
DOCX
Automation Frame works Instruction Sheet
PPT
BDD with JBehave and Selenium
PDF
How to Un-Flake Flaky Tests - A New Hire's Toolkit
ODP
Testing In Java4278
PPTX
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
PPTX
QAorHighway2016
PDF
Flaky No More: Find the Right Framework for Your Selenium Tests
PDF
How to Un-Flake Flaky Tests - A New Hire's Toolkit
How To Use Selenium Successfully
Behavior Driven Development (BDD) and Agile Testing
How To Use Selenium Successfully
Automated Acceptance Tests in .NET
Behavior Driven Development and Automation Testing Using Cucumber
Selenium course training institute ameerpet hyderabad – Best software trainin...
Jbehave selenium
Continuous Testing Meets the Classroom at Code.org
Perils of Page-Object Pattern
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...
Introduction to SoapUI day 1
Sharing the pain using Protractor
Automation Frame works Instruction Sheet
BDD with JBehave and Selenium
How to Un-Flake Flaky Tests - A New Hire's Toolkit
Testing In Java4278
Automate testing with behat, selenium, phantom js and nightwatch.js (5)
QAorHighway2016
Flaky No More: Find the Right Framework for Your Selenium Tests
How to Un-Flake Flaky Tests - A New Hire's Toolkit
Ad

Viewers also liked (20)

PPTX
Interface grafica em_java_parte_iii
PPTX
Samui Luxury Villas - The Estates Samui
PPTX
Twitterとfacebook
PPTX
Visual answers to everyday challenges
PPT
Каталог товаров с сайта Racingplanet.de
PPSX
SolTec Presentation
PDF
Solutions Simplified - Taking advantage of Cloud
PPT
Rickwebslidedeck 1
PPT
Tracy cv for web 2011
PDF
Modulo a
PPTX
Introduction to Kanban
PPTX
Depth Consulting - Calgary .NET User Group - Apr 22 2015 - Dependency Injection
PPTX
Unlock the hidden value in your membership data presentation overview only
PPTX
Album de fotos
PDF
Social Media Wist-u-dat?
PPTX
Agile Games
PPTX
PPTX
Interface grafica em_java_parte_ii
PPTX
Introduction to kanban calgary .net user group - feb 6
PPTX
Ta cs jed v3
Interface grafica em_java_parte_iii
Samui Luxury Villas - The Estates Samui
Twitterとfacebook
Visual answers to everyday challenges
Каталог товаров с сайта Racingplanet.de
SolTec Presentation
Solutions Simplified - Taking advantage of Cloud
Rickwebslidedeck 1
Tracy cv for web 2011
Modulo a
Introduction to Kanban
Depth Consulting - Calgary .NET User Group - Apr 22 2015 - Dependency Injection
Unlock the hidden value in your membership data presentation overview only
Album de fotos
Social Media Wist-u-dat?
Agile Games
Interface grafica em_java_parte_ii
Introduction to kanban calgary .net user group - feb 6
Ta cs jed v3
Ad

Similar to Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth Consulting (20)

PDF
How to use selenium successfully
PPTX
Browser Automated Testing Frameworks - Nightwatch.js
PDF
Exploratory Testing As Code Eurostar23
PDF
Exploratory Testing As Code
PDF
Testing - How Vital and How Easy to use
PPTX
Behavior Driven Development
PDF
Agile Testing 2020
PPTX
Java 201 Intro to Test Driven Development in Java
PPTX
Acceptance Test Driven Development
PDF
Escaping Test Hell - ACCU 2014
PPTX
Dev/Test scenarios in DevOps world
PPTX
Test team dynamics, Антон Мужайло
PPTX
Test Driven Development & CI/CD
PPTX
Continuous Delivery - Automate & Build Better Software with Travis CI
PDF
Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality
PDF
CNUG TDD June 2014
PPTX
2014 Joker - Integration Testing from the Trenches
ODP
Testing In Java
PDF
An Automation Culture: The Key to Agile Success
PDF
AgileTesting_Ver1.0
How to use selenium successfully
Browser Automated Testing Frameworks - Nightwatch.js
Exploratory Testing As Code Eurostar23
Exploratory Testing As Code
Testing - How Vital and How Easy to use
Behavior Driven Development
Agile Testing 2020
Java 201 Intro to Test Driven Development in Java
Acceptance Test Driven Development
Escaping Test Hell - ACCU 2014
Dev/Test scenarios in DevOps world
Test team dynamics, Антон Мужайло
Test Driven Development & CI/CD
Continuous Delivery - Automate & Build Better Software with Travis CI
Droidcon Spain 2016 - The Pragmatic Android Programmer: from hype to reality
CNUG TDD June 2014
2014 Joker - Integration Testing from the Trenches
Testing In Java
An Automation Culture: The Key to Agile Success
AgileTesting_Ver1.0

Recently uploaded (20)

PPTX
Introduction to Artificial Intelligence
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
history of c programming in notes for students .pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Digital Strategies for Manufacturing Companies
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
ai tools demonstartion for schools and inter college
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
System and Network Administraation Chapter 3
PPTX
L1 - Introduction to python Backend.pptx
Introduction to Artificial Intelligence
Computer Software and OS of computer science of grade 11.pptx
Upgrade and Innovation Strategies for SAP ERP Customers
Designing Intelligence for the Shop Floor.pdf
Softaken Excel to vCard Converter Software.pdf
Reimagine Home Health with the Power of Agentic AI​
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
history of c programming in notes for students .pptx
Odoo Companies in India – Driving Business Transformation.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Digital Strategies for Manufacturing Companies
How to Choose the Right IT Partner for Your Business in Malaysia
Digital Systems & Binary Numbers (comprehensive )
Internet Downloader Manager (IDM) Crack 6.42 Build 41
ai tools demonstartion for schools and inter college
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PTS Company Brochure 2025 (1).pdf.......
Wondershare Filmora 15 Crack With Activation Key [2025
System and Network Administraation Chapter 3
L1 - Introduction to python Backend.pptx

Unit Testing - Calgary .NET User Group - Nov 26 2014 - Depth Consulting