Unit Testing with NUnit<br />Ron Klein<br />http://heblog.ronklein.co.il <br />http://tinyurl.com/ronklein<br />
Agenda<br />Introduction to Unit Testing<br />Basic Examples with NUnit<br />Why Unit Testing?<br />Advanced Features (if ...
Introduction to Unit Testing<br />Tests<br />Tests<br />Tests<br />Code<br />
What's a Unit?<br />Unit == class || method<br />Unit != classes.Count > 1<br />
How to test?<br />Manually? –possible, but not so friendly<br />Automated Frameworks:<br />NUnit<br />MSTest<br />MbUnit<b...
Testing Framework<br />A set of code and tools to test existing code<br />Testing code is decorated with attributes<br />T...
Demo – Array Util<br />The task:<br />A method has 2 input parameters:<br />A non empty, sorted array of integers<br />An ...
Why Unit Testing?<br />Unit Testing is a STANDARD<br />No need to manually test code by console applications<br />Accepted...
Why Unit Testing?<br />Fearlessly Change Implementation<br />(back to demo)<br />
Why Unit Testing?<br />Leads us to Better Code / Better Design<br />Demo: Greet example<br />
I Can't Test That Code<br />More than a single class is used<br />Even worse: Singletons are used<br />Hardware boundaries...
Unit Testing<br />More code to test our code<br />Unit Testing Leads to:<br />Fearlessly Change Implementation<br />Better...
Resources<br />NUnit: http://nunit.org/<br />Moq: http://code.google.com/p/moq/<br />
Thank You!<br />
Upcoming SlideShare
Loading in...5
×

Unit testing with NUnit

5,241

Published on

What it unit testing, what's a unit, how to test?

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
5,241
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
87
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Unit testing with NUnit

  1. 1. Unit Testing with NUnit<br />Ron Klein<br />http://heblog.ronklein.co.il <br />http://tinyurl.com/ronklein<br />
  2. 2. Agenda<br />Introduction to Unit Testing<br />Basic Examples with NUnit<br />Why Unit Testing?<br />Advanced Features (if we have time)<br />
  3. 3. Introduction to Unit Testing<br />Tests<br />Tests<br />Tests<br />Code<br />
  4. 4. What's a Unit?<br />Unit == class || method<br />Unit != classes.Count > 1<br />
  5. 5. How to test?<br />Manually? –possible, but not so friendly<br />Automated Frameworks:<br />NUnit<br />MSTest<br />MbUnit<br />etc.<br />
  6. 6. Testing Framework<br />A set of code and tools to test existing code<br />Testing code is decorated with attributes<br />Testing Framework uses Reflection to invoke testing code<br />Most tests either Passor Fail<br />
  7. 7. Demo – Array Util<br />The task:<br />A method has 2 input parameters:<br />A non empty, sorted array of integers<br />An integer<br />The output should be the closest number from the array to the input number.<br />"Closest" in terms of absolute value<br />Try to write it yourself!<br />
  8. 8. Why Unit Testing?<br />Unit Testing is a STANDARD<br />No need to manually test code by console applications<br />Accepted by Developers <br />Expected by Developers<br />Fearlessly Change Implementation<br />
  9. 9. Why Unit Testing?<br />Fearlessly Change Implementation<br />(back to demo)<br />
  10. 10. Why Unit Testing?<br />Leads us to Better Code / Better Design<br />Demo: Greet example<br />
  11. 11. I Can't Test That Code<br />More than a single class is used<br />Even worse: Singletons are used<br />Hardware boundaries:<br />System Clock<br />HTTP Requests<br />File Read/Write<br />Refactor!<br />
  12. 12. Unit Testing<br />More code to test our code<br />Unit Testing Leads to:<br />Fearlessly Change Implementation<br />Better Code / Better Design<br />If a class can't be tested – consider refactoring<br />Legacy code is code without tests<br />
  13. 13. Resources<br />NUnit: http://nunit.org/<br />Moq: http://code.google.com/p/moq/<br />
  14. 14. Thank You!<br />
  1. A particular slide catching your eye?

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

×