Unit Testing with NUnitRon Kleinhttp://heblog.ronklein.co.il http://tinyurl.com/ronklein
AgendaIntroduction to Unit TestingBasic Examples with NUnitWhy Unit Testing?Advanced Features (if we have time)
Introduction to Unit TestingTestsTestsTestsCode
What's a Unit?Unit == class || methodUnit != classes.Count > 1
How to test?Manually? –possible, but not so friendlyAutomated Frameworks:NUnitMSTestMbUnitetc.
Testing FrameworkA set of code and tools to test existing codeTesting code is decorated with attributesTesting Framework uses Reflection to invoke testing codeMost tests either Passor Fail
Demo – Array UtilThe task:A method has 2 input parameters:A non empty, sorted array of integersAn integerThe output should be the closest number from the array to the input number."Closest" in terms of absolute valueTry to write it yourself!
Why Unit Testing?Unit Testing is a STANDARDNo need to manually test code by console applicationsAccepted by Developers Expected by DevelopersFearlessly Change Implementation
Why Unit Testing?Fearlessly Change Implementation(back to demo)
Why Unit Testing?Leads us to Better Code / Better DesignDemo: Greet example
I Can't Test That CodeMore than a single class is usedEven worse: Singletons are usedHardware boundaries:System ClockHTTP RequestsFile Read/WriteRefactor!
Unit TestingMore code to test our codeUnit Testing Leads to:Fearlessly Change ImplementationBetter Code / Better DesignIf a class can't be tested – consider refactoringLegacy code is code without tests
ResourcesNUnit: http://nunit.org/Moq: http://code.google.com/p/moq/
Thank You!

Unit testing with NUnit

  • 1.
    Unit Testing withNUnitRon Kleinhttp://heblog.ronklein.co.il http://tinyurl.com/ronklein
  • 2.
    AgendaIntroduction to UnitTestingBasic Examples with NUnitWhy Unit Testing?Advanced Features (if we have time)
  • 3.
    Introduction to UnitTestingTestsTestsTestsCode
  • 4.
    What's a Unit?Unit== class || methodUnit != classes.Count > 1
  • 5.
    How to test?Manually?–possible, but not so friendlyAutomated Frameworks:NUnitMSTestMbUnitetc.
  • 6.
    Testing FrameworkA setof code and tools to test existing codeTesting code is decorated with attributesTesting Framework uses Reflection to invoke testing codeMost tests either Passor Fail
  • 7.
    Demo – ArrayUtilThe task:A method has 2 input parameters:A non empty, sorted array of integersAn integerThe output should be the closest number from the array to the input number."Closest" in terms of absolute valueTry to write it yourself!
  • 8.
    Why Unit Testing?UnitTesting is a STANDARDNo need to manually test code by console applicationsAccepted by Developers Expected by DevelopersFearlessly Change Implementation
  • 9.
    Why Unit Testing?FearlesslyChange Implementation(back to demo)
  • 10.
    Why Unit Testing?Leadsus to Better Code / Better DesignDemo: Greet example
  • 11.
    I Can't TestThat CodeMore than a single class is usedEven worse: Singletons are usedHardware boundaries:System ClockHTTP RequestsFile Read/WriteRefactor!
  • 12.
    Unit TestingMore codeto test our codeUnit Testing Leads to:Fearlessly Change ImplementationBetter Code / Better DesignIf a class can't be tested – consider refactoringLegacy code is code without tests
  • 13.
  • 14.