unit and functional testing for ios platform

Upload: adiawinta

Post on 02-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    1/81

    Christopher M. Judd

    Unit and FunctionalTesting for the iOS

    Platform

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    2/81

    Christopher M. JuddPresident/Consultant of

    leader

    Columbus Developer User Group (CIDUG)

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    3/81

    Remarkable Ohio

    Free

    Developed for eTech Ohio and Ohio Historical Center

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    4/81

    University System Of Ohio

    FreeDeveloped for eTech Ohio and University System Of Ohio

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    5/81

    Chmod

    Free Judd Solutions

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    6/81

    December 2008 issue

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    7/81

    How many of you are currently orhave developed applications for the

    iOS Platform?

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    8/81

    How many of you have ever unit or

    functionally tested your iOS

    application?

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    9/81

    How many of you have ever

    unit tested on anotherplatform or language?

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    10/81

    Why arent you testingyour iOS applications?

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    11/81Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    12/81

    iOS unit and functional testing is

    neither straight forward or easyThursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    13/81

    iOS Unit Testing Challenges

    Toooo many steps to get startedNo green bar/red bar

    Cant run individual testsUnit test template code contains to muchUnit tests can not be debugged out of the box

    Little documentationMultiple targetsOnly includes very basic testing support

    No mock framework included

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    14/81

    iOS Functional Testing Challenges

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    15/81

    iOS Functional Testing Challenges

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    16/81

    Testing Coverage

    The Objective-C Programming Language

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    17/81

    Testing Coverage

    The Objective-C Programming Language

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    18/81

    Unit Testing

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    19/81

    Unit Testing Basics

    Thursday, January 13, 2011

    Wh U i T ?

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    20/81

    Why Unit Test?

    Improves designFacility change and refactoringSimplifies integrationProvides executable documentation

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    21/81

    includes also known as

    SenTestingKit

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    22/81

    Logic Test == Unit TestApplication Test == More Functional Test

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    23/81

    Getting Started

    Thursday, January 13, 2011

    S d i

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    24/81

    http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-

    Unit_Testing_Applications/unit_testing_applications.html#/

    apple_ref/doc/uid/TP40007959-CH20-SW3

    Setup documentation

    Thursday, January 13, 2011

    S d i

    http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    25/81

    http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-

    Unit_Testing_Applications/unit_testing_applications.html#/

    apple_ref/doc/uid/TP40007959-CH20-SW3

    Setup documentation

    or

    ios developer guide unit testing

    Thursday, January 13, 2011

    U it T ti S t St

    http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/135-Unit_Testing_Applications/unit_testing_applications.html%23//apple_ref/doc/uid/TP40007959-CH20-SW3
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    26/81

    Unit Testing Setup Steps

    1. Add unit test bundle target

    2. Make unit test target active3. Add group for test classes4. Add unit test class

    Thursday, January 13, 2011

    Add U it T t B dl T t

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    27/81

    Add Unit Test Bundle Target

    Thursday, January 13, 2011

    M k U it T t T t A ti

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    28/81

    Make Unit Test Target Active

    Thursday, January 13, 2011

    Add G f T t Cl

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    29/81

    Add Group for Test Classes

    Thursday, January 13, 2011

    Add U it T t Cl

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    30/81

    Add Unit Test Class

    Should end in TestShould be in a separate directory

    Must be have UnitTeststarget checked

    Thursday, January 13, 2011

    G t d T t Cl

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    31/81

    Generated Test Class*Test.h

    *Test.m

    Thursday, January 13, 2011

    Generated Test Class

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    32/81

    Generated Test Class*Test.h

    *Test.m

    Thursday, January 13, 2011

    Create Custom User Templates

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    33/81

    Create Custom User Templates

    *Test.m

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    34/81

    !B

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    35/81

    !Bor

    Build > Build

    with unit test targetselected

    or

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    36/81

    False

    Nothing to

    worry aboutReal FailureThursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    37/81

    Writing Unit Tests

    Thursday, January 13, 2011

    Basic Unit Test

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    38/81

    Basic Unit Test

    *Test.m must extend SenTestCase

    must return void andtake no parameters

    test methods mustbegin with test

    Thursday, January 13, 2011

    Assert Macros

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    39/81

    Assert Macros

    STAssertNil(a1, description, ...)

    STAssertNotNil(a1, description, ...)

    STAssertTrue(expression, description, ...)

    STAssertFalse(expression, description, ...)

    STAssertEqualObjects(a1, a2, description, ...)

    STAssertEquals(a1, a2, description, ...)

    STAssertEqualsWithAccuracy(left, right, accuracy, description, ...)

    STAssertThrows(expression, description, ...)STAssertThrowsSpecific(expression, specificException, description, ...)

    STAssertThrowsSpecificNamed(expr, specificException, aName, description, ...)

    STAssertNoThrow(expression, description, ...)

    STAssertNoThrowSpecific(expression, specificException, description, ...)

    STAssertNoThrowSpecificNamed(expr, specificException, aName, description, ...)

    STFail(description, ...)

    STAssertTrueNoThrow(expression, description, ...)STAssertFalseNoThrow(expression, description, ...)

    Thursday, January 13, 2011

    Basic Unit Test Example

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    40/81

    Basic Unit Test Example

    *Test.m

    Thursday, January 13, 2011

    Test Target

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    41/81

    - (void) testSimple {

    Simple* simple = [[[Simplealloc] init] retain];

    STAssertEquals(3, [simple coolMethod], @"");

    [simple release];}

    Test TargetClasses under test must also target Test target or

    add your application target as direct dependency

    Solutions

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    42/81

    Debugging Unit Tests

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    43/81

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    44/81

    NSLog does not even work by default

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    45/81

    http://www.grokkingcocoa.com/how_to_debug_iphone_unit_te.htmlThursday, January 13, 2011

    http://www.grokkingcocoa.com/how_to_debug_iphone_unit_te.htmlhttp://www.grokkingcocoa.com/how_to_debug_iphone_unit_te.html
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    46/81

    Delete the Run Script

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    47/81

    Delete the Run Script

    Delete

    Thursday, January 13, 2011

    Create otest Executable

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    48/81

    /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/

    iPhoneSimulator3.1.sdk/Developer/usr/bin/otest

    Create otest Executable

    Thursday, January 13, 2011

    Configure Arguments

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    49/81

    Configure Argumentsname of

    unit testbundle

    I dontevenknow

    Thursday, January 13, 2011

    Run Tests

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    50/81

    Run Testswith unit test target and

    executable selected !

    orBuild > Build and Go

    test resultsThursday, January 13, 2011

    Run Tests

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    51/81

    Run Testswith unit test target and

    executable selected !

    orBuild > Build and Go

    test resultsNo more RedbarThursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    52/81

    Additional

    Unit TestingThoughts

    Thursday, January 13, 2011

    http://www.mulle-kybernetik.com/software/OCMock/

    http://www.mulle-kybernetik.com/software/OCMock/http://www.mulle-kybernetik.com/software/OCMock/
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    53/81

    p y

    hamcrest http://code.google.com/p/hamcrest/

    http://code.google.com/p/uispec/

    Thursday, January 13, 2011

    http://code.google.com/p/uispec/http://code.google.com/p/uispec/http://code.google.com/p/hamcrest/http://code.google.com/p/hamcrest/http://www.mulle-kybernetik.com/software/OCMock/
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    54/81

    Functional Testing

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    55/81

    UI Automation

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    56/81

    Included in

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    57/81

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    58/81

    Device Simulator

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    59/81

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    60/81

    Running

    UI AutomationScripts

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    61/81

    1. Start Instruments

    2. Select Automation Instrument

    3. Select Target App4. Select Script5. Record (Play)

    Thursday, January 13, 2011

    Test Results

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    62/81

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    63/81

    Element Tree

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    64/81

    UIATarget

    UIAApplication

    UIAWindow

    UIANavigationBar

    UIATableViewUIATableCell

    Element Tree

    UIATarget.localTarget().frontMostApp() .mainWindow().tableViews()[0].cells()[0]

    Thursday, January 13, 2011

    Technique to visualize element tree

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    65/81

    UIATarget.localTarget() .logElementTree();

    q

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    66/81

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    67/81

    Instead of

    window.scrollViews()[0].textViews()[0].setValue("CodeMash is cool!!!");

    window.scrollViews()[0].textViews()["note"].setValue("CodeMash is cool!!!");

    use

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    68/81

    UITarget.localTarget().captureScreenWithName("help_screen");

    Does not work in simulator :(

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    69/81

    When things dont work

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    70/81

    When things dont work

    UIATarget.delay(1);

    add

    Thursday, January 13, 2011

    Make it easier with tuneup

    https://github.com/alexvollmer/tuneup_jshttps://github.com/alexvollmer/tuneup_jshttps://github.com/alexvollmer/tuneup_js
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    71/81

    Make it easier with tuneupprovides templates and asserts

    https://github.com/alexvollmer/tuneup_jsThursday, January 13, 2011

    Page Object

    https://github.com/alexvollmer/tuneup_jshttps://github.com/alexvollmer/tuneup_jshttps://github.com/alexvollmer/tuneup_jshttps://github.com/alexvollmer/tuneup_jshttps://github.com/alexvollmer/tuneup_jshttps://github.com/alexvollmer/tuneup_jshttps://github.com/alexvollmer/tuneup_jshttp://www.cheezyworld.com/2010/11/09/ui-tests-not-brittle/
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    72/81

    http://www.cheezyworld.com/2010/11/09/ui-tests-not-brittle/Thursday, January 13, 2011

    http://www.cheezyworld.com/2010/11/09/ui-tests-not-brittle/http://www.cheezyworld.com/2010/11/09/ui-tests-not-brittle/http://www.cheezyworld.com/2010/11/09/ui-tests-not-brittle/
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    73/81

    works with other instrumentscan run in the simulator or the device

    no command-line automationno fixtures (setup, teardown)

    difficult to debug (element tree & delays)little documentationtest run must be manually stopped

    Thursday, January 13, 2011

    UI Automation Resources

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    74/81

    UI Automation Resources

    UI Automation Reference Collectionhttp://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html

    Session 306 - Automation User Interface Testing withInstruments

    Thursday, January 13, 2011

    http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.htmlhttp://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    75/81

    iCuke

    https://github.com/unboxed/icukeThursday, January 13, 2011

    Cuke Script

    https://github.com/unboxed/icukehttps://github.com/unboxed/icukehttps://github.com/unboxed/icuke
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    76/81

    Cuke Script

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    77/81

    can be automatedhuman readableeasy to write

    can only run on simulator

    little documentationcan not run in instruments

    Thursday, January 13, 2011

    Resources

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    78/81

    http://pragprog.com/magazines/2010-07/bdd-on-iphone-icukeThursday, January 13, 2011

    Great iOS Resources

    http://pragprog.com/magazines/2010-07/bdd-on-iphone-icukehttp://pragprog.com/magazines/2010-07/bdd-on-iphone-icuke
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    79/81

    Great iOS Resources

    The Objective-C Programming Language

    Thursday, January 13, 2011

  • 8/11/2019 Unit and Functional Testing for Ios Platform

    80/81

    President/Consultant/Author

    email: [email protected]

    web: www.juddsolutions.com

    blog: juddsolutions.blogspot.comtwitter: javajudd

    Christopher M. Judd

    Thursday, January 13, 2011

    Attributions

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]
  • 8/11/2019 Unit and Functional Testing for Ios Platform

    81/81

    http://www.organicdesign.co.nz/File:Warning.svg

    Attributions

    http://www.flickr.com/photos/heliotrop3/4310957752/

    http://www.flickr.com/photos/heliotrop3/4310957752/http://www.flickr.com/photos/heliotrop3/4310957752/http://www.organicdesign.co.nz/File:Warning.svghttp://www.organicdesign.co.nz/File:Warning.svg