Slide 1

Slide 1 text

Unit Testing Prashant

Slide 2

Slide 2 text

Before we start… • Unit tests are “Code” • Not efficient to test the UI • Unit testing is not a testing activity.

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Demo

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Continued… • Inject dependencies and state via constructor • Avoid classes coupled to many other classes • Avoid classes coupled to concrete classes rather than interfaces

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

questions ? Thanks…