SlideShare una empresa de Scribd logo
1 de 9
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 ?

Más contenido relacionado

La actualidad más candente

UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
suhasreddy1
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
nickokiss
 

La actualidad más candente (20)

Junit
JunitJunit
Junit
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 
Test automation process
Test automation processTest automation process
Test automation process
 
What is JUnit? | Edureka
What is JUnit? | EdurekaWhat is JUnit? | Edureka
What is JUnit? | Edureka
 
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
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Introduction to Software Test Automation
Introduction to Software Test AutomationIntroduction to Software Test Automation
Introduction to Software Test Automation
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in Angular
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
Mockito
MockitoMockito
Mockito
 
Testing Angular
Testing AngularTesting Angular
Testing Angular
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
Unit Test
Unit TestUnit Test
Unit Test
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 

Destacado

Destacado (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 ...
 
Unit testing with NUnit
Unit testing with NUnitUnit testing with NUnit
Unit testing with NUnit
 
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
 
N Unit Presentation
N Unit PresentationN Unit Presentation
N Unit Presentation
 
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
 

Similar a Unit Testing (C#)

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
Dan Poltawski
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
MaslowB
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
MaslowB
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
Meilan Ou
 

Similar a 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 ?