Unit Testing & Test Driven Development

31
SOFTWARE UNİT TESTİNG AND TEST DRİVEN DEVELOPMENT WİTH NUNİT FRAMEWORK by Ersan BİLİK

description

A presentation of mine at universtiy...

Transcript of Unit Testing & Test Driven Development

Page 1: Unit Testing & Test Driven Development

SOFTWARE UNİT TESTİNGAND

TEST DRİVEN DEVELOPMENT WİTH NUNİT FRAMEWORK

byErsan BİLİK

Page 2: Unit Testing & Test Driven Development

So.. What is Unit Testing ?

unit : smallest testable part of an application an individual program a function a procedure a method.. depends on your

viewpoint !

Page 3: Unit Testing & Test Driven Development

So.. What is Unit Testing (cont’d)

test: a means of determining the presence, quality or truth of something determining “the unit” works as it is promised

to? determining the quality of “the unit” ? determining the truth about “the unit” ?

Page 4: Unit Testing & Test Driven Development

So.. What is Unit Testing ? (cont’d)

Unit Testing : a procedure used to validate that individual units of source code are working properly. unit testing itself, is a procedure unit testing applies to individual units unit tests build-on to source code

to ensure source code is working properly

Page 5: Unit Testing & Test Driven Development

Where Unit Testing lies in Software Development Life Cycle ?

Unit testing is a white box approach in testing activity

usually, it is integrated with implementation phase but also, it depends on your software development life cycle..

Page 6: Unit Testing & Test Driven Development

What about cons and pros ?

PROS CONS

isolation of units refactoring code simplifies integration documentation seperation of interface

from implementation a good habit: motivator

for decoupled, cohesive code bodies, refactored with design patterns..

go to definition: it applies to individual units, therefore it can not guaranty the overall system will work !

it only shows the presence of errors, not absence of errors..

Page 7: Unit Testing & Test Driven Development

How to apply it ?

Manually.. step by step instructional document..

Automated tools frameworks are available.. usually called xUnit frameworks..

Page 8: Unit Testing & Test Driven Development

tell us.. HOW !

we will investigate test driven development methodology with nUnit framework based on Microsoft .NET

Page 9: Unit Testing & Test Driven Development

Test Driven Development ???

an approach for software development actually, itself is not a lifecycle model,

but an approach for implementation phase for agile software lifecycles..

it is a bottom-up approach.. think: write tests first, then code

necessary instructions to pass your tests..

Page 10: Unit Testing & Test Driven Development

Write tests first ???

yes, first write a test case. then build it.. it will fail because no code

written to pass the test implement your code as long as test case

is passed.. and voila..! YAGNI : you aint gonna need

it. So, you code as much as you need.. then think about it, how to do it better ?

Page 11: Unit Testing & Test Driven Development

Lets Code a simple Account Class

Page 12: Unit Testing & Test Driven Development

Lets Code it’s Unit Test

Page 13: Unit Testing & Test Driven Development

Now, run nUnit GUI to check results

Page 14: Unit Testing & Test Driven Development

Implement the necessary code..

Page 15: Unit Testing & Test Driven Development

Run the test again..

Page 16: Unit Testing & Test Driven Development

Are we done ?

is the code satisfies my requirements ? lets assume requirements sais: if a

customer wants to transfer money, minimum balance for the customer should be 10.00$

so, lets continue..

Page 17: Unit Testing & Test Driven Development

Add Minimum Balance field/property

Page 18: Unit Testing & Test Driven Development

Add an exception in case of overdraft

Page 19: Unit Testing & Test Driven Development

Write a new test method

Page 20: Unit Testing & Test Driven Development

Run the test

Page 21: Unit Testing & Test Driven Development

Code to generate necessary exception

Page 22: Unit Testing & Test Driven Development

Run the Test

Page 23: Unit Testing & Test Driven Development

Room for improvement

Page 24: Unit Testing & Test Driven Development

Run the Test

Page 25: Unit Testing & Test Driven Development

Handle ambiguity

Page 26: Unit Testing & Test Driven Development

thinking about transaction..

Page 27: Unit Testing & Test Driven Development

Refactor Test Code

Page 28: Unit Testing & Test Driven Development

Run the test

Page 29: Unit Testing & Test Driven Development

What should we know more ?

mock objects and their usage in unit testing..

Page 30: Unit Testing & Test Driven Development

Beyond test driven development

Check out Behaviour Driven Development

Watch video of Dave Astels ( co-author of “A

practical guide to eXtreme Programming” and author of award winning test-driven development: a practical guide)

Page 31: Unit Testing & Test Driven Development

Thanks for your patience : )

any questions or comments ?