Unit testing with NUnit
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Unit testing with NUnit

on

  • 5,106 views

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

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

Statistics

Views

Total Views
5,106
Views on SlideShare
2,264
Embed Views
2,842

Actions

Likes
0
Downloads
55
Comments
0

5 Embeds 2,842

http://heblog.ronklein.co.il 2788
http://feeds.feedburner.com 44
http://coderwall.com 7
http://translate.googleusercontent.com 2
http://www.google.co.il 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Unit testing with NUnit Presentation Transcript

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