Giter Club home page Giter Club logo

mttestsemaphore's Introduction

MTTestSemaphore

A class to help you create unit tests that test asynchronous methods. You will need this to unit test any class that fetch data from the network, use location, camera, etc.

How to include MTTestSemaphore in your project

Clone this repo from https://github.com/icanzilb/MTTestSemaphore or download it as a zip file.

Include the contents of the MTTestSemaphore sub-folder in your project - make sure that the MTTestSemaphore class is included in your Test target.

How to use MTTestSemaphore in your unit tests

Use [[MTTestSemaphore semaphore] waitForKey: @"myAwesomeKey"] to stop the code execution at a given place and wait (ie wait for your asynchronious code to finish executing)

Use [[MTTestSemaphore semaphore] lift: @"myAwesomeKey"] to un-block the program execution at the place where you stopped it for the same key.

Here's a complete example, how to make an async call in a test case and wait for its execution:

-(void)testLocationAsyncNoComments
{
    NSString* sempahoreKey = @"testLocationAsync1";

    CLGeocoder* gc = [[CLGeocoder alloc] init];
    [gc geocodeAddressString:@"Triq Sant' Orsla, Valletta, Malta"
           completionHandler:^(NSArray *placemarks, NSError *error) {
               
               NSAssert(placemarks.count>0, @"the geocoder returned 0 results");
               [[MTTestSemaphor semaphore] lift: sempahoreKey];
               
           }];
    
    [[MTTestSemaphor semaphore] waitForKey: sempahoreKey];
}

Download and run Project/Test the project included in this repo, to see the usage of MTTestSemaphore

mttestsemaphore's People

Contributors

icanzilb avatar rudensm avatar

Watchers

James Cloos avatar Ricardo Silva avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.