Top Banner
Unit Testing Abhinav Gujjar @abhinavgujjar
28
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Unit testing

Unit Testing

Abhinav Gujjar

@abhinavgujjar

Page 2: Unit testing

RULES!

Mobiles on Silent modeAskAskAsk again

Page 3: Unit testing

Agenda

What is Unit TestingWhy unit test ?Unit Testing Frameworks for .NetBest Practices for unit testingTest Driven Development (TDD)Unit testing in Agile

Page 4: Unit testing

Urgh – Not my job

I’m a Developer. I don’t test.

I pay testers for testing

Page 5: Unit testing

In The Real World

Page 6: Unit testing

In The Real World

Page 7: Unit testing

Different Types of Testing

Development Testing Deployment

Unit Testing Functional Testing

Integration Testing

Acceptance Testing

Page 8: Unit testing

DEMO

Simple Interest Calculation

Page 9: Unit testing

What?

You are already doing it… But not correctly

Prove the correctness of a small isolated piece of functionality in a larger system

Page 10: Unit testing

Why?

Higher QualityBetter CodeDocumentation

Page 11: Unit testing

How?

Unit Testing Frameworks.Net

nUnit xUnitmsTest

Page 12: Unit testing

Demo

Creating unit tests

Page 13: Unit testing

Anatomy

Unit Test Framework

Unit Tests

Arrange

Act

Assert

Page 14: Unit testing

Red-Green Refactor Cycle

Red

GreenRefactor

Page 15: Unit testing

One Assert per test

One logical assertion per testMay need more than one Assert statement

Page 16: Unit testing

Qualities of a Unit Test

RepeatableIndependent

Page 17: Unit testing

Exercise

Writing Tests

Page 18: Unit testing

Testing the Sad Path

Page 19: Unit testing

Assertions !

Simple Assertions Collection AssertsString Asserts

Page 20: Unit testing

Test Setup and Tear Downs

AssemblyClassTest

Page 21: Unit testing

Isolating Code

Page 22: Unit testing

Isolation Techniques

DummiesStubsFake – Maintain StateSpy – Maintains state and is available for assertionMock – Complex behavior

Page 23: Unit testing

Mocking Frameworks

MoqRhinoMocksnMock

Page 24: Unit testing

Silverlight Unit Testing

Tests are run on the browserMoq available! Yay !But - Only if you use the MVVM pattern

View Model First Approach

Page 25: Unit testing

Refactoring

When is done done ?Code may be correct

But is it healthy?

Readability

Maintainability

What about performance ?

Technical Debt

Page 26: Unit testing

Code Smells

Duplicated Code

Long Method

Long Parameter List

Large Class

Comments !!

Switch statements

Dead Code

Page 27: Unit testing

Testing Legacy Code

Why?When?How?

Page 28: Unit testing

Happy Unit Testing!

Blog: www.rubiksquare.com

Discussion: http://www.rubiksquare.com/p/discuss.html

LinkedIn : http://www.linkedin.com/in/abhinavgujjar

mail: [email protected]