jeudi 14 février 2013

My experience with iOS automated testing frameworks

On my current iOS project, the focus on quality naturally pushed me to go further in automated testing.

They run locally, on simulator, on device and in CI.

Unit tests


GHUnit: http://gabriel.github.com/gh-unit/
OCMockito: https://github.com/jonreid/OCMockito
OCHamcrest: https://github.com/hamcrest/OCHamcrest

Pros


  • GHUnit support for asynchronous operations
  • Ease of use of OCMockito and OCHamcrest

Cons

?

KIF

https://github.com/square/KIF

Pros


  • Run fast and consistently
  • Easy access to the application objects since the tests are written in Objective C
  • Extensible

Cons


  • Tests language is not QA/Client friendly

Extension for long tap / press

As a new method of UIView+KIFAdditions (thanks to: http://blog.dimaj.net/content/howto-long-press-kif ) :

- (void)longTapAtPoint:(CGPoint)point withDelay:(NSInteger)delay andCompletion:(void(^)(void)) completion
{
    // Handle touches in the normal way for other views
    UITouch *touch = [[UITouch alloc] initAtPoint:point inView:self];
    [touch setPhase:UITouchPhaseBegan];
    
    // Create the touch event and send it to the application
    UIEvent *event = [self _eventWithTouch:touch];
    [[UIApplication sharedApplication] sendEvent:event];
    
    // Perform long touch
    dispatch_after( dispatch_time( DISPATCH_TIME_NOW, NSEC_PER_SEC * delay), dispatch_get_current_queue(), ^(void){
        [touch setPhase:UITouchPhaseEnded];
        [[UIApplication sharedApplication] sendEvent:event];
        
        // Dispatching the event doesn't actually update the first responder, so fake it
        if ([touch.view isDescendantOfView:self] && [self canBecomeFirstResponder]) {
            [self becomeFirstResponder];
        }
        
        if (completion) completion();
    });
    
    // Release the touch
    [touch release];
}

Calaba.sh

http://calaba.sh

Pros


  • Tests in Gherkin langage, BDD Cucumber
  • Powerful CSS like selectors
  • Gesture recording and playback : you can record complex gesture
  • iOS and Android support

Cons



  • Issues with the execution of tests where the interaction with the UI stopped working, did not find why (Button tap not working in some scenarios only)
  • Execution of test action not very reliable: gestures stop working, maybe issues with the embedded calaba.sh server.


Aucun commentaire: