SlideShare a Scribd company logo
Unit Testing in Action
C# NUnit, and Moq
15 Sep. 2021
Presented By &
Unit Testing in Action - C# NUnit, and Moq
XP Days xpdays.org is an initiative
for gathering people interested in
Agile, eXtreme Programming (aka:
XP), Scrum, Coding, etc.
XP is a lightweight, efficient, and low-
risk Agile Software Development
Framework intended to improve
software quality.
Agile Arena agilearena.net is an Agile
Consulting and Training company. specialized in
agile adoption and transformation for companies
and teams through:
• Designing their agile adoption programs
• Executing our programs and guiding the team
through their journey to sustainable agility .
• We also provide accredited training classes
for companies and individuals
This Webinar
is Held By:
Mohammed Shaban
Presented By &
AGENDA
• Unit Testing
• NUnit
• Moq
Unit Testing in Action - C# NUnit, and Moq
What we’ll be covering this webinar
Presented By &
What is automated testing?
• Automated testing is the practice of writing code to test our code, and then
run those tests in an automated fashion.
• Automated tests are repeatable
Unit Testing in Action - C# NUnit, and Moq
Presented By &
Why automated testing
• You can test our application code on a frequent basis and in less time.
• Catch bugs BEFORE deploying.
• Deploy with confidence.
• Refactor with confidence.
• Focus more on the quality.
* Refactoring means changing the structure of your code, without changing
its behavior.
Unit Testing in Action - C# NUnit, and Moq
Presented By &
Types of Automated Test
• Unit
• Test a unit of an application without its external dependencies.
• Cheap to write and fast to execute don’t give a lot of confidence.
• Integration
• Test the application with its dependencies.
• Take longer to execute and give more confidence.
• E2E
• Drives an application through its UI.
• Give you the greatest confidence and very slow and very brittle.
Unit Testing in Action - C# NUnit, and Moq
Presented By &
Testing framework
• NUnit
• MSTest
• xUnit
Unit Testing in Action - C# NUnit, and Moq
Presented By &
TDD
• With TDD you write your tests before writing the production code.
• Write a failing test.
• Write the simplest code to make the test pass.
• Refactor if necessary.
Unit Testing in Action - C# NUnit, and Moq
Presented By &
Benefits of TDD
• Testable source code.
• Full coverage by tests.
• Simpler implementation.
Unit Testing in Action - C# NUnit, and Moq
Presented By &
Good Unit Tests
• First class citizens.
• Clean , readable and maintainable.
• No logic.
• Isolated.
• Not too specific/general.
Unit Testing in Action - C# NUnit, and Moq
NUnit Demo
Presented By &
• Simple Unit Test
• Set Up and Tear Down
• Parameterized Tests
• Ignoring Tests
• Testing Strings
• Testing Arrays and Collections
• Testing the Return Type of Methods
• Testing Void Methods
• Testing Methods that Throw Exceptions
• Testing Methods that Raise an Event
• Testing Private Methods
Unit Testing in Action - C# NUnit, and Moq
NUnit Demo
Presented By &
• In software engineering, dependency injection is a technique whereby one
object (or static method) supplies the dependencies of another object. A
dependency is an object that can be used (a service).
Unit Testing in Action - C# NUnit, and Moq
DI
Presented By &
• Constructor Injection: In the constructor injection, the injector supplies the
service (dependency) through the client class constructor.
• Property Injection: In the property injection (aka the Setter Injection), the
injector supplies the dependency through a public property of the client
class.
• Method Injection: In this type of injection, the client class implements an
interface which declares the method(s) to supply the dependency and the
injector uses this interface to supply the dependency to the client class.
Unit Testing in Action - C# NUnit, and Moq
Types of dependency injection
Presented By &
• Moq
• NSubstitue
• FakeItEasy
• Rhino Mocks
Unit Testing in Action - C# NUnit, and Moq
Mocking Frameworks
Moq Demo
Presented By &
www.agilearena.net
www.xpdays.org
Unit Testing in Action - C# NUnit, and Moq
Presented By &
DISCUSSION
Unit Testing in Action - C#
NUnit, and Moq
OPEN DISUCSSION

More Related Content

What's hot (20)

PDF
Dependency Injection in iOS
Pablo Villar
Ā 
PDF
Agile Programming Systems # TDD intro
Vitaliy Kulikov
Ā 
PPT
TDD (Test Driven Design)
nedirtv
Ā 
PDF
An Introduction to Test Driven Development
CodeOps Technologies LLP
Ā 
PPT
Test Driven Development
Sachithra Gayan
Ā 
PPT
Unit testing
dubbu
Ā 
KEY
Unit Testing Your Application
Paladin Web Services
Ā 
PPTX
Unit tests benefits
Kate Semizhon
Ā 
PDF
Test Driven Development
Mireia Sangalo
Ā 
PPTX
Test Driven Development
Sergey Aganezov
Ā 
PDF
Unit testing legacy code
Lars Thorup
Ā 
PPTX
Test Driven Development (TDD) Preso 360|Flex 2010
guest5639fa9
Ā 
PPTX
A Brief Introduction to Test-Driven Development
Shawn Jones
Ā 
PPTX
TDD Basics with Angular.js and Jasmine
Luis SƔnchez Castellanos
Ā 
PPTX
Understanding Unit Testing
ikhwanhayat
Ā 
PPS
Unit Testing
Anuj Arora
Ā 
PDF
Behavior Driven Development with SpecFlow
Rachid Kherrazi
Ā 
PPT
Scrum and Test-driven development
toteb5
Ā 
PDF
Test Driven iOS Development (TDD)
Babul Mirdha
Ā 
PPTX
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove
Ā 
Dependency Injection in iOS
Pablo Villar
Ā 
Agile Programming Systems # TDD intro
Vitaliy Kulikov
Ā 
TDD (Test Driven Design)
nedirtv
Ā 
An Introduction to Test Driven Development
CodeOps Technologies LLP
Ā 
Test Driven Development
Sachithra Gayan
Ā 
Unit testing
dubbu
Ā 
Unit Testing Your Application
Paladin Web Services
Ā 
Unit tests benefits
Kate Semizhon
Ā 
Test Driven Development
Mireia Sangalo
Ā 
Test Driven Development
Sergey Aganezov
Ā 
Unit testing legacy code
Lars Thorup
Ā 
Test Driven Development (TDD) Preso 360|Flex 2010
guest5639fa9
Ā 
A Brief Introduction to Test-Driven Development
Shawn Jones
Ā 
TDD Basics with Angular.js and Jasmine
Luis SƔnchez Castellanos
Ā 
Understanding Unit Testing
ikhwanhayat
Ā 
Unit Testing
Anuj Arora
Ā 
Behavior Driven Development with SpecFlow
Rachid Kherrazi
Ā 
Scrum and Test-driven development
toteb5
Ā 
Test Driven iOS Development (TDD)
Babul Mirdha
Ā 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove
Ā 

Similar to Unit Testing in Action - C#, NUnit, and Moq (20)

PPTX
Testing Best Practices
Axway Appcelerator
Ā 
PDF
An Introduction to Unit Test Using NUnit
weili_at_slideshare
Ā 
PPTX
Concepts of unit testing_dynamic-testing.ppt.pptx
ssuser9d6aac
Ā 
PPTX
Concepts of unit testing_dynamic-testing.ppt.pptx
ssuser9d6aac
Ā 
PPTX
Structured system analysis and design
Jayant Dalvi
Ā 
PPT
Software testing concepts
satyatwrmca
Ā 
PDF
Software testing methods, levels and types
Confiz
Ā 
PPTX
An Introduction to Unit Testing
Sahar Nofal
Ā 
PPT
Test Driven Development using QUnit
satejsahu
Ā 
PDF
Shift Remote: Mobile - Efficiently Building Native Frameworks for Multiple Pl...
Shift Conference
Ā 
PPTX
Appmotives - Software Testing As Service
Kalyan Paluri
Ā 
PDF
Agile Testing
Intelliware Development Inc.
Ā 
PDF
Agile Testing - What is it?
Intelliware Development Inc.
Ā 
PPTX
Tools for Software Testing
Mohammed Moishin
Ā 
PDF
Accelerating tests with Cypress for a leaderboard platform
Knoldus Inc.
Ā 
PPTX
software testing
Sara shall
Ā 
KEY
Client Side Unit Testing
cloud chen
Ā 
PDF
Enter the mind of an Agile Developer
BSGAfrica
Ā 
PPTX
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Jacinto Limjap
Ā 
PDF
manualtesting-170218090020 (1).pdf
peramdevi06
Ā 
Testing Best Practices
Axway Appcelerator
Ā 
An Introduction to Unit Test Using NUnit
weili_at_slideshare
Ā 
Concepts of unit testing_dynamic-testing.ppt.pptx
ssuser9d6aac
Ā 
Concepts of unit testing_dynamic-testing.ppt.pptx
ssuser9d6aac
Ā 
Structured system analysis and design
Jayant Dalvi
Ā 
Software testing concepts
satyatwrmca
Ā 
Software testing methods, levels and types
Confiz
Ā 
An Introduction to Unit Testing
Sahar Nofal
Ā 
Test Driven Development using QUnit
satejsahu
Ā 
Shift Remote: Mobile - Efficiently Building Native Frameworks for Multiple Pl...
Shift Conference
Ā 
Appmotives - Software Testing As Service
Kalyan Paluri
Ā 
Agile Testing - What is it?
Intelliware Development Inc.
Ā 
Tools for Software Testing
Mohammed Moishin
Ā 
Accelerating tests with Cypress for a leaderboard platform
Knoldus Inc.
Ā 
software testing
Sara shall
Ā 
Client Side Unit Testing
cloud chen
Ā 
Enter the mind of an Agile Developer
BSGAfrica
Ā 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Jacinto Limjap
Ā 
manualtesting-170218090020 (1).pdf
peramdevi06
Ā 
Ad

More from XPDays (20)

PPTX
Change the Conversation! Unleash Your Potential in a Complex World.pptx
XPDays
Ā 
PDF
Agile Culture Transformation
XPDays
Ā 
PDF
Re-engineering Technology to break barriers with Business
XPDays
Ā 
PPTX
Practicing Red, Green, Refactor!
XPDays
Ā 
PPTX
Ready, Steady, Sprint
XPDays
Ā 
PPTX
The Whole Story of The User Story
XPDays
Ā 
PPTX
Scrum Master Facilitation Techniques
XPDays
Ā 
PPTX
An Introduction to The Cynefin Framework
XPDays
Ā 
PPTX
Team Mental Health
XPDays
Ā 
PPTX
Business Analyst in the Agile Space
XPDays
Ā 
PPTX
DevOps in action - Azure DevOps
XPDays
Ā 
PPTX
Priotrization techniques
XPDays
Ā 
PPTX
Scaled Agile Framework
XPDays
Ā 
PDF
Building Team Habits
XPDays
Ā 
PPTX
4 Keys to Success in your Agile Journey
XPDays
Ā 
PPTX
Coaching stances
XPDays
Ā 
PPTX
Re-focus for Agile leaders
XPDays
Ā 
PPTX
Business Decomposition
XPDays
Ā 
PPTX
Agile projects | Prioritization
XPDays
Ā 
PPTX
Scaling Agile | Spotify
XPDays
Ā 
Change the Conversation! Unleash Your Potential in a Complex World.pptx
XPDays
Ā 
Agile Culture Transformation
XPDays
Ā 
Re-engineering Technology to break barriers with Business
XPDays
Ā 
Practicing Red, Green, Refactor!
XPDays
Ā 
Ready, Steady, Sprint
XPDays
Ā 
The Whole Story of The User Story
XPDays
Ā 
Scrum Master Facilitation Techniques
XPDays
Ā 
An Introduction to The Cynefin Framework
XPDays
Ā 
Team Mental Health
XPDays
Ā 
Business Analyst in the Agile Space
XPDays
Ā 
DevOps in action - Azure DevOps
XPDays
Ā 
Priotrization techniques
XPDays
Ā 
Scaled Agile Framework
XPDays
Ā 
Building Team Habits
XPDays
Ā 
4 Keys to Success in your Agile Journey
XPDays
Ā 
Coaching stances
XPDays
Ā 
Re-focus for Agile leaders
XPDays
Ā 
Business Decomposition
XPDays
Ā 
Agile projects | Prioritization
XPDays
Ā 
Scaling Agile | Spotify
XPDays
Ā 
Ad

Recently uploaded (20)

PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
Ā 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
Ā 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
Ā 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
Ā 
PDF
ā€œComputer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,ā€ a ...
Edge AI and Vision Alliance
Ā 
PDF
ā€œVoice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
Ā 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
Ā 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
Ā 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
Ā 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
Ā 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
Ā 
PDF
Kit-Works Team Study_20250627_ķ•œė‹¬ė§Œģ—ė§Œė“ ģ‚¬ė‚“ģ„œė¹„ģŠ¤ķ‚¤ė§(ģ–‘ė‹¤ģœ—).pdf
Wonjun Hwang
Ā 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
Ā 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
Ā 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
Ā 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
Ā 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
Ā 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
Ā 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
Ā 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
Ā 
Mastering Financial Management in Direct Selling
Epixel MLM Software
Ā 
The Project Compass - GDG on Campus MSIT
dscmsitkol
Ā 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
Ā 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
Ā 
ā€œComputer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,ā€ a ...
Edge AI and Vision Alliance
Ā 
ā€œVoice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
Ā 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
Ā 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
Ā 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
Ā 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
Ā 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
Ā 
Kit-Works Team Study_20250627_ķ•œė‹¬ė§Œģ—ė§Œė“ ģ‚¬ė‚“ģ„œė¹„ģŠ¤ķ‚¤ė§(ģ–‘ė‹¤ģœ—).pdf
Wonjun Hwang
Ā 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
Ā 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
Ā 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
Ā 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
Ā 
How do you fast track Agentic automation use cases discovery?
DianaGray10
Ā 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
Ā 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
Ā 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
Ā 

Unit Testing in Action - C#, NUnit, and Moq

  • 1. Unit Testing in Action C# NUnit, and Moq 15 Sep. 2021
  • 2. Presented By & Unit Testing in Action - C# NUnit, and Moq XP Days xpdays.org is an initiative for gathering people interested in Agile, eXtreme Programming (aka: XP), Scrum, Coding, etc. XP is a lightweight, efficient, and low- risk Agile Software Development Framework intended to improve software quality. Agile Arena agilearena.net is an Agile Consulting and Training company. specialized in agile adoption and transformation for companies and teams through: • Designing their agile adoption programs • Executing our programs and guiding the team through their journey to sustainable agility . • We also provide accredited training classes for companies and individuals
  • 3. This Webinar is Held By: Mohammed Shaban
  • 4. Presented By & AGENDA • Unit Testing • NUnit • Moq Unit Testing in Action - C# NUnit, and Moq What we’ll be covering this webinar
  • 5. Presented By & What is automated testing? • Automated testing is the practice of writing code to test our code, and then run those tests in an automated fashion. • Automated tests are repeatable Unit Testing in Action - C# NUnit, and Moq
  • 6. Presented By & Why automated testing • You can test our application code on a frequent basis and in less time. • Catch bugs BEFORE deploying. • Deploy with confidence. • Refactor with confidence. • Focus more on the quality. * Refactoring means changing the structure of your code, without changing its behavior. Unit Testing in Action - C# NUnit, and Moq
  • 7. Presented By & Types of Automated Test • Unit • Test a unit of an application without its external dependencies. • Cheap to write and fast to execute don’t give a lot of confidence. • Integration • Test the application with its dependencies. • Take longer to execute and give more confidence. • E2E • Drives an application through its UI. • Give you the greatest confidence and very slow and very brittle. Unit Testing in Action - C# NUnit, and Moq
  • 8. Presented By & Testing framework • NUnit • MSTest • xUnit Unit Testing in Action - C# NUnit, and Moq
  • 9. Presented By & TDD • With TDD you write your tests before writing the production code. • Write a failing test. • Write the simplest code to make the test pass. • Refactor if necessary. Unit Testing in Action - C# NUnit, and Moq
  • 10. Presented By & Benefits of TDD • Testable source code. • Full coverage by tests. • Simpler implementation. Unit Testing in Action - C# NUnit, and Moq
  • 11. Presented By & Good Unit Tests • First class citizens. • Clean , readable and maintainable. • No logic. • Isolated. • Not too specific/general. Unit Testing in Action - C# NUnit, and Moq
  • 13. Presented By & • Simple Unit Test • Set Up and Tear Down • Parameterized Tests • Ignoring Tests • Testing Strings • Testing Arrays and Collections • Testing the Return Type of Methods • Testing Void Methods • Testing Methods that Throw Exceptions • Testing Methods that Raise an Event • Testing Private Methods Unit Testing in Action - C# NUnit, and Moq NUnit Demo
  • 14. Presented By & • In software engineering, dependency injection is a technique whereby one object (or static method) supplies the dependencies of another object. A dependency is an object that can be used (a service). Unit Testing in Action - C# NUnit, and Moq DI
  • 15. Presented By & • Constructor Injection: In the constructor injection, the injector supplies the service (dependency) through the client class constructor. • Property Injection: In the property injection (aka the Setter Injection), the injector supplies the dependency through a public property of the client class. • Method Injection: In this type of injection, the client class implements an interface which declares the method(s) to supply the dependency and the injector uses this interface to supply the dependency to the client class. Unit Testing in Action - C# NUnit, and Moq Types of dependency injection
  • 16. Presented By & • Moq • NSubstitue • FakeItEasy • Rhino Mocks Unit Testing in Action - C# NUnit, and Moq Mocking Frameworks
  • 18. Presented By & www.agilearena.net www.xpdays.org Unit Testing in Action - C# NUnit, and Moq
  • 19. Presented By & DISCUSSION Unit Testing in Action - C# NUnit, and Moq OPEN DISUCSSION