Unit Testing Basics


                 Serhiy Oplakanets @ Mavenresearch, November 2010
                  Slides are not intended to make sense outside of the talk.

Thursday, November 18, 2010
A Discipline
                   •          Unit Testing is a discipline of Quality Assurance

                   •          Others Include:

                         •      Functional Testing

                         •      Integration Testing

                         •      Code Review

                         •      Continuous Integration

                         •      ...


Thursday, November 18, 2010
Unit Testing is


                   • validating that individual units of
                              application work properly




Thursday, November 18, 2010
Benefits
                   •          Finding bugs early

                   •          Less debugging

                   •          Changes to application are safer and easier

                   •          Examples of code usage

                   •          Documentation (to some extent)

                   •          Unit test is a tool to validate code design; in most
                              cases code that is hard to test is badly designed


Thursday, November 18, 2010
Good Unit Test
                   •          Test only one unit at a time

                   •          Do not depend on ordering of test run

                   •          Runs fast

                   •          Tests only one feature at a time

                   •          Easy to understand

                   •          Tests the public API of unit

                   •          Covers all usage cases


Thursday, November 18, 2010
Test Suite

                   • Multiple tests form Test Suite
                   • Your most important tool to check impact
                              of changes
                   • Helps estimate changes


Thursday, November 18, 2010
Good Unit Test Suite

                   • Is simple to run
                   • Runs fast (preferable in seconds)
                   • Is always Green
                   • Is non-interactive

Thursday, November 18, 2010
Limitations of Unit Testing
                   •          Not every bug can be found by unit tests

                   •          As we're testing only one module -- integration
                              issues are not covered

                   •          Multi-threaded issues can't be caught by one-
                              threaded test

                   •          Hardware failures, 3rd party component issues,
                              etc. All those can be covered only with a proper
                              Functional Test Suite



Thursday, November 18, 2010
Practical Session



Thursday, November 18, 2010
Resources
                   • http://en.wikipedia.org/wiki/Unit_testing :)
                   • http://blog.stevensanderson.com/
                              2009/08/24/writing-great-unit-tests-best-
                              and-worst-practises/
                   • http://googletesting.blogspot.com/2008/11/
                              clean-code-talks-unit-testing.html
                   • http://geosoft.no/development/
Thursday, November 18, 2010
Thank you.



Thursday, November 18, 2010

Unit Testing Basics

  • 1.
    Unit Testing Basics Serhiy Oplakanets @ Mavenresearch, November 2010 Slides are not intended to make sense outside of the talk. Thursday, November 18, 2010
  • 2.
    A Discipline • Unit Testing is a discipline of Quality Assurance • Others Include: • Functional Testing • Integration Testing • Code Review • Continuous Integration • ... Thursday, November 18, 2010
  • 3.
    Unit Testing is • validating that individual units of application work properly Thursday, November 18, 2010
  • 4.
    Benefits • Finding bugs early • Less debugging • Changes to application are safer and easier • Examples of code usage • Documentation (to some extent) • Unit test is a tool to validate code design; in most cases code that is hard to test is badly designed Thursday, November 18, 2010
  • 5.
    Good Unit Test • Test only one unit at a time • Do not depend on ordering of test run • Runs fast • Tests only one feature at a time • Easy to understand • Tests the public API of unit • Covers all usage cases Thursday, November 18, 2010
  • 6.
    Test Suite • Multiple tests form Test Suite • Your most important tool to check impact of changes • Helps estimate changes Thursday, November 18, 2010
  • 7.
    Good Unit TestSuite • Is simple to run • Runs fast (preferable in seconds) • Is always Green • Is non-interactive Thursday, November 18, 2010
  • 8.
    Limitations of UnitTesting • Not every bug can be found by unit tests • As we're testing only one module -- integration issues are not covered • Multi-threaded issues can't be caught by one- threaded test • Hardware failures, 3rd party component issues, etc. All those can be covered only with a proper Functional Test Suite Thursday, November 18, 2010
  • 9.
  • 10.
    Resources • http://en.wikipedia.org/wiki/Unit_testing :) • http://blog.stevensanderson.com/ 2009/08/24/writing-great-unit-tests-best- and-worst-practises/ • http://googletesting.blogspot.com/2008/11/ clean-code-talks-unit-testing.html • http://geosoft.no/development/ Thursday, November 18, 2010
  • 11.