Affichage des articles dont le libellé est ios. Afficher tous les articles
Affichage des articles dont le libellé est ios. Afficher tous les articles

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.


lundi 10 décembre 2012

Embedding a Core Data model from a static library project

In one of my project, I want to share a Core Data model between 2 projects. I have a common static library project where the model and classes are defined.

Situation


  • a common project that builds a static library which contains my Core Data model (to be shared with an iOS and an OSX project)
  • my main iOS project

Problem

  • static library cannot include resources
  • how can I give make my main project use the Core Data model ?

Solution

  • Create a new target of type Bundle (in OSX/Frameworks and Library)
  • Change the build settings of this target:
    • Base SDK:  Latest iOS 
    • Supported platform: iOS
    • Valid architecture: arm architecture
  • Add your model file (.xcdatamodeld) to the Build phases / Compile Sources section of the bundle target
  • Link your bundle with Core Data (add it to Build phase / Link Binary section)
  • Build the bundle target
Now in your main project:
  • Select the project to show Build Phases / Copy Bundle Resources
  • Drag the Bundle target product (from Products group in the project navigator) to the Copy Bundle Resources section
  • If it s not already there, add your static library: in Build Phases / Link binary section, use the "+" button to add your static library file
  • Load the model from the bundle:
NSString *staticLibraryBundlePath = [[NSBundle mainBundle] pathForResource:@"ModelBundle" ofType:@"bundle"];

NSURL *staticLibraryMOMURL = [[NSBundle bundleWithPath:staticLibraryBundlePath] URLForResource:@"MyDataModel" withExtension:@"momd"];

model = [[NSManagedObjectModel alloc] initWithContentsOfURL:staticLibraryMOMURL];