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 /...
It’s good unit test, if…•   One Unit Test Class per “Class”•   Each test should run in isolation•   Test should be clear• ...
Demo
Recommendations•   Use Mocking frameworks•   Mark classes and Interfaces as internal•   When refactoring think of architec...
Continued…• Inject dependencies and state via constructor• Avoid classes coupled to many other classes• Avoid classes coup...
References• Rhino Mocks  – http://www.ayende.com/Wiki/Rhino+Mocks+3.5.    ashx#WhatsNewinRhinoMocksDF• Nunit  – http://www...
Thanks…          questions ?
Upcoming SlideShare
Loading in...5
×

Unit Testing (C#)

1,020

Published on

My super boring unit test slides

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,020
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Unit Testing (C#)

  1. 1. Unit Testing Prashant
  2. 2. Before we start…• Unit tests are “Code”• Not efficient to test the UI• Unit testing is not a testing activity.
  3. 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. 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
  5. 5. Demo
  6. 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. 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. 8. References• Rhino Mocks – http://www.ayende.com/Wiki/Rhino+Mocks+3.5. ashx#WhatsNewinRhinoMocksDF• Nunit – http://www.nunit.org• Mocks Arent Stubs (Martin Fowler) – http://martinfowler.com/articles/mocksArentStub s.html
  9. 9. Thanks… questions ?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×