Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Unit testing_pps


Published on

Published in: Technology, Education
  • A good starting point; Thank you!
    Are you sure you want to  Yes  No
    Your message goes here

Unit testing_pps

  1. 1. Unit Testing framework in iOS
  2. 2. What? <ul><li>What is Unit-Testing? </li></ul><ul><li>Available Unit Testing frameworks for iOS. </li></ul><ul><li>Basics of OCUnit Testing. </li></ul>
  3. 3. Unit Testing <ul><li>A Paradigm of Test-driven development. </li></ul><ul><li>Mainly of two types: </li></ul><ul><ul><li>Logic Unit Testing </li></ul></ul><ul><ul><ul><li>Testing a smallest logical unit or methods. </li></ul></ul></ul><ul><ul><li>Application Unit Testing </li></ul></ul><ul><ul><ul><li>Testing an entire application. </li></ul></ul></ul>
  4. 4. Unit Testing Frameworks <ul><li>Family of similar frameworks for testing various languages </li></ul><ul><ul><li>Junit, Nunit, PyUnit etc. </li></ul></ul><ul><li>OCUnit for Objective-C </li></ul><ul><ul><li>Ships with MAC OS X developer tools, </li></ul></ul><ul><ul><li>Included in iPhone sdk 2.2. </li></ul></ul>
  5. 5. Why? <ul><li>Fewer Bugs </li></ul><ul><ul><li>More confidence that you’re shipping a high quality product. </li></ul></ul><ul><li>Find bugs early . </li></ul><ul><ul><li>Bugs are easier (and cheaper) to fix early in development. </li></ul></ul><ul><li>Avoid regressions </li></ul><ul><ul><li>Ensures that changing one piece of code doesn’t breaks another. </li></ul></ul><ul><li>Document your code </li></ul>
  6. 6. When and Who? <ul><li>When: </li></ul><ul><ul><li>Parallel to development. </li></ul></ul><ul><li>Who: </li></ul><ul><ul><li>Developer . </li></ul></ul>
  7. 7. How? <ul><li>Tests are ideally written along with new code (and even before the new code). </li></ul><ul><li>Test-driven development: </li></ul><ul><ul><li>Write test first. </li></ul></ul><ul><ul><li>Fill in the implementation untill test pas. </li></ul></ul><ul><ul><li>Rinse and repeat. </li></ul></ul>
  8. 8. Running Unit Tests <ul><li>Automate so you don’t have to explicitly run tests. </li></ul><ul><li>Many testing frameworks can run tests every time you build. </li></ul><ul><li>Compiler checks SYNTAX . UnitTest check SEMANTICS </li></ul>
  9. 9. OCUnit A Unit Testing framework for iOS
  10. 10. History <ul><li>1998 - Written by Sen:te. </li></ul><ul><ul><li>Objective C becomes onr of the first language to benefit from this approach of testing. </li></ul></ul><ul><li>2002 –Presented at WWDC. </li></ul><ul><li>2005 – Apple decided to integrate it in Xcode 2.1. </li></ul><ul><li>2008 – Apple actually integrated OCUnit in iPhone sdk 2.2 </li></ul>
  11. 11. <ul><li>SenTestCases is abstract test superclass </li></ul><ul><li>Automatically runs methods thath begin with “test” </li></ul><ul><li>Macros for asserting conditions during tests. </li></ul>OCUnit
  12. 12. Asserts Macros
  13. 13. Example #import <SenTestingKit/SenTestingKit.h> #import <UIKit/UIKit.h> @class Person; @interface Person TestClass : SenTestCase { Person *personObj; //create the reference of the class to be tested } @end
  14. 14. Example #import &quot;PersonTestClass.h&quot; #import &quot;Person.h&quot; @implementation PersonTestClass -(void)testCreatePerson { personObj= [[Person alloc] init]; STAssertNotNil (personObj, @&quot;A Person Object was never created&quot;); } @end
  15. 15. DEMO A Unit Testing framework for iOS