SlideShare a Scribd company logo
Unit Testing

  Prashant
Before we start…
• Unit tests are “Code”
• Not efficient to test the UI
• Unit testing is not a testing activity.
Why unit testing?
• Acts as specifications for your code / business
  requirements
• Helps to produce better code (Readable /
  Maintainable)
• Make you think before you write any code
It’s good unit test, if…
•   One Unit Test Class per “Class”
•   Each test should run in isolation
•   Test should be clear
•   Single outcome per test
•   Name Tests from Users Perspective
    – Long test method names.
    – Conventions
Demo
Recommendations
•   Use Mocking frameworks
•   Mark classes and Interfaces as internal
•   When refactoring think of architecture
•   Consider splitting class into multiple files
•   Avoid using Static classes/Methods
•   UI Containing non-user logic
Continued…
• Inject dependencies and state via constructor
• Avoid classes coupled to many other classes
• Avoid classes coupled to concrete classes
  rather than interfaces
References
• Rhino Mocks
  – http://www.ayende.com/Wiki/Rhino+Mocks+3.5.
    ashx#WhatsNewinRhinoMocksDF
• Nunit
  – http://www.nunit.org
• Mocks Aren't Stubs (Martin Fowler)
  – http://martinfowler.com/articles/mocksArentStub
    s.html
Thanks…




          questions ?

More Related Content

What's hot

UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 
Introduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveIntroduction to Robot Framework – Exove
Introduction to Robot Framework – Exove
Exove
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Shailendra Chauhan
 
Unit testing
Unit testing Unit testing
Unit testing
Mani Kanth
 
Software testing
Software testingSoftware testing
Software testing
Omar Al-Bokari
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
Pokpitch Patcharadamrongkul
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-conceptsmedsherb
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
Francesco Garavaglia
 
testng
testngtestng
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
Nayanda Haberty
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Anuj Arora
 
Introduction to Automation Testing
Introduction to Automation TestingIntroduction to Automation Testing
Introduction to Automation Testing
Archana Krushnan
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
Bethmi Gunasekara
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi
 
Junit
JunitJunit
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test PresentationSayedur Rahman
 
Data Driven Testing
Data Driven TestingData Driven Testing
Data Driven TestingMaveryx
 

What's hot (20)

UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Introduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveIntroduction to Robot Framework – Exove
Introduction to Robot Framework – Exove
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Unit testing
Unit testing Unit testing
Unit testing
 
Software testing
Software testingSoftware testing
Software testing
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
testng
testngtestng
testng
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Introduction to Automation Testing
Introduction to Automation TestingIntroduction to Automation Testing
Introduction to Automation Testing
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Junit
JunitJunit
Junit
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
 
N Unit Presentation
N Unit PresentationN Unit Presentation
N Unit Presentation
 
Data Driven Testing
Data Driven TestingData Driven Testing
Data Driven Testing
 

Viewers also liked

Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
Frank Appel
 
Moq Presentation
Moq PresentationMoq Presentation
Moq Presentation
LynxStar
 
Mock driven development using .NET
Mock driven development using .NETMock driven development using .NET
Mock driven development using .NET
Puneet Ghanshani
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
Stephen Fuqua
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
weili_at_slideshare
 
All about unit testing using (power) mock
All about unit testing using (power) mockAll about unit testing using (power) mock
All about unit testing using (power) mock
Pranalee Rokde
 
Sequential file programming patterns and performance with .net
Sequential  file programming patterns and performance with .netSequential  file programming patterns and performance with .net
Sequential file programming patterns and performance with .net
Michael Pavlovsky
 
Nuget is easier than you think and you should be using it as both a consumer ...
Nuget is easier than you think and you should be using it as both a consumer ...Nuget is easier than you think and you should be using it as both a consumer ...
Nuget is easier than you think and you should be using it as both a consumer ...
Justin James
 
Using nu get the way you should svcc
Using nu get the way you should   svccUsing nu get the way you should   svcc
Using nu get the way you should svcc
Maarten Balliauw
 
Using NuGet the way you should - TechDays NL 2014
Using NuGet the way you should - TechDays NL 2014Using NuGet the way you should - TechDays NL 2014
Using NuGet the way you should - TechDays NL 2014
Maarten Balliauw
 
Pentium microprocessor
Pentium microprocessorPentium microprocessor
Pentium microprocessor
tanzidshawon
 
Developing NuGet
Developing NuGetDeveloping NuGet
Developing NuGet
Jeff Handley
 
Unit tests for dummies
Unit tests for dummiesUnit tests for dummies
Unit tests for dummies
cpsitgmbh
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!
Return on Intelligence
 
NUnit Features Presentation
NUnit Features PresentationNUnit Features Presentation
NUnit Features Presentation
Shir Brass
 
Easymock Tutorial
Easymock TutorialEasymock Tutorial
Easymock Tutorial
Sbin m
 
Techniques in black box testing
Techniques in black box testingTechniques in black box testing
Techniques in black box testingDuy Tan Geek
 

Viewers also liked (20)

Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
Moq Presentation
Moq PresentationMoq Presentation
Moq Presentation
 
Mock driven development using .NET
Mock driven development using .NETMock driven development using .NET
Mock driven development using .NET
 
Principles and patterns for test driven development
Principles and patterns for test driven developmentPrinciples and patterns for test driven development
Principles and patterns for test driven development
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
All about unit testing using (power) mock
All about unit testing using (power) mockAll about unit testing using (power) mock
All about unit testing using (power) mock
 
Sequential file programming patterns and performance with .net
Sequential  file programming patterns and performance with .netSequential  file programming patterns and performance with .net
Sequential file programming patterns and performance with .net
 
Nuget is easier than you think and you should be using it as both a consumer ...
Nuget is easier than you think and you should be using it as both a consumer ...Nuget is easier than you think and you should be using it as both a consumer ...
Nuget is easier than you think and you should be using it as both a consumer ...
 
Using nu get the way you should svcc
Using nu get the way you should   svccUsing nu get the way you should   svcc
Using nu get the way you should svcc
 
Using NuGet the way you should - TechDays NL 2014
Using NuGet the way you should - TechDays NL 2014Using NuGet the way you should - TechDays NL 2014
Using NuGet the way you should - TechDays NL 2014
 
Pentium microprocessor
Pentium microprocessorPentium microprocessor
Pentium microprocessor
 
Developing NuGet
Developing NuGetDeveloping NuGet
Developing NuGet
 
Nunit
NunitNunit
Nunit
 
Unit tests for dummies
Unit tests for dummiesUnit tests for dummies
Unit tests for dummies
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!
 
NUnit Features Presentation
NUnit Features PresentationNUnit Features Presentation
NUnit Features Presentation
 
Easymock Tutorial
Easymock TutorialEasymock Tutorial
Easymock Tutorial
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
Types of pattern
Types of patternTypes of pattern
Types of pattern
 
Techniques in black box testing
Techniques in black box testingTechniques in black box testing
Techniques in black box testing
 

Similar to Unit Testing (C#)

Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
Benjamin Baumann
 
Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019
Grzegorz Miejski
 
Software Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry PracticesSoftware Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry Practices
Alfred Jett Grandeza
 
How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreDan Poltawski
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
Bhavin Gandhi
 
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
 
Clean code
Clean codeClean code
Clean code
Simon Sönnby
 
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
 
CNUG TDD June 2014
CNUG TDD June 2014CNUG TDD June 2014
CNUG TDD June 2014
Mayank Srivastava
 
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
 
Building iOS App Project & Architecture
Building iOS App Project & ArchitectureBuilding iOS App Project & Architecture
Building iOS App Project & Architecture
Massimo Oliviero
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
Bccon use notes objects in memory and other useful
Bccon   use notes objects in memory and other usefulBccon   use notes objects in memory and other useful
Bccon use notes objects in memory and other useful
Frank van der Linden
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
Sahar Nofal
 
Clean tests
Clean testsClean tests
Clean tests
Agileee
 
How to write test in node.js
How to write test in node.jsHow to write test in node.js
How to write test in node.js
Jason Lin
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
Nacho Cougil
 

Similar to Unit Testing (C#) (20)

Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019Tests immutable when refactoring - SegFault Unconference Cracow 2019
Tests immutable when refactoring - SegFault Unconference Cracow 2019
 
Software Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry PracticesSoftware Engineering - Trends & Industry Practices
Software Engineering - Trends & Industry Practices
 
How to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle coreHow to guarantee your change is integrated to Moodle core
How to guarantee your change is integrated to Moodle core
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
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
 
Clean code
Clean codeClean code
Clean code
 
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)
 
CNUG TDD June 2014
CNUG TDD June 2014CNUG TDD June 2014
CNUG TDD June 2014
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)
 
Building iOS App Project & Architecture
Building iOS App Project & ArchitectureBuilding iOS App Project & Architecture
Building iOS App Project & Architecture
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Bccon use notes objects in memory and other useful
Bccon   use notes objects in memory and other usefulBccon   use notes objects in memory and other useful
Bccon use notes objects in memory and other useful
 
An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
Clean tests
Clean testsClean tests
Clean tests
 
How to write test in node.js
How to write test in node.jsHow to write test in node.js
How to write test in node.js
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
 

Unit Testing (C#)

  • 1. Unit Testing Prashant
  • 2. Before we start… • Unit tests are “Code” • Not efficient to test the UI • Unit testing is not a testing activity.
  • 3. Why unit testing? • Acts as specifications for your code / business requirements • Helps to produce better code (Readable / Maintainable) • Make you think before you write any code
  • 4. It’s good unit test, if… • One Unit Test Class per “Class” • Each test should run in isolation • Test should be clear • Single outcome per test • Name Tests from Users Perspective – Long test method names. – Conventions
  • 6. Recommendations • Use Mocking frameworks • Mark classes and Interfaces as internal • When refactoring think of architecture • Consider splitting class into multiple files • Avoid using Static classes/Methods • UI Containing non-user logic
  • 7. Continued… • Inject dependencies and state via constructor • Avoid classes coupled to many other classes • Avoid classes coupled to concrete classes rather than interfaces
  • 8. References • Rhino Mocks – http://www.ayende.com/Wiki/Rhino+Mocks+3.5. ashx#WhatsNewinRhinoMocksDF • Nunit – http://www.nunit.org • Mocks Aren't Stubs (Martin Fowler) – http://martinfowler.com/articles/mocksArentStub s.html
  • 9. Thanks… questions ?