Skip to content

C Macro's to wait for any async test and get an STFail in your test if it exceeds time limit

License

Notifications You must be signed in to change notification settings

aarsland/AGAsyncTestHelper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AGAsyncTestHelper

C Macro for writing unit tests with asynchronous operations. Works perfectly with SenTestingKit!

Example blocks

- (void)testDoSomeOperation
{
    __block BOOL jobDone = NO;

    [Manager doSomeOperationOnDone:^(id data) {
        jobDone = YES; 
    }];

    WAIT_WHILE(!jobDone, 2.0);
}

WAIT_WHILE() will stall current runloop while !jobDone is TRUE and throw an STFail if exceeding time limit (2.0 seconds)

Example plain callback / delegate

- (void)testDoSomeOperation
{
    [Manager doSomeOperationOnDoneTellTarget:self selector:@selector(someOperationDone)];

    WAIT_WHILE(!self.jobDone, 2.0);
}

- (void)someOperationDone
{
    self.jobDone = YES;
}

WAIT_WHILE() will stall current runloop while !self.jobDone is TRUE and throw an STFail if exceeding time limit (2.0 seconds)

Advantages

  • Minimum code
  • Error thrown in the test. Since it is based on macro's the exception will not be thrown in some 3rd party implementation file further down the stack
  • Small library
  • Works perfectly with SenTestingKit
  • No known bugs or issues

Overview

The macro will evaluate the expression while the expression is true or the time limit is reached.

These macros will generate STFail() if time limit is reached.

WAIT_WHILE(expressionIsTrue, limitInSeconds)
WAIT_WHILE_WITH_DESC(expressionIsTrue, seconds, description, ...)
WAIT_WHILE_EQUALS(value1, value2, limitInSeconds)
WAIT_WHILE_EQUALS_WITH_DESC(value1, value2, limitInSeconds, description, ...)
WAIT_WHILE_EQUALS_WITH_ACCURACY(value1, value2, accuracy, limitInSeconds)
WAIT_WHILE_EQUALS_WITH_ACCURACY_WITH_DESC(value1, value2, accuracy, limitInSeconds, description, ...)
WAIT_WHILE_NOT_EQUALS(value, value2, limitInSeconds)
WAIT_WHILE_NOT_EQUALS_WITH_DESC(value1, value2, limitInSeconds, description, ...)
AG_STALL_RUNLOPP_WHILE(expressionIsTrue, limitInSeconds)

Alternatives

You've got several alternatives like

If you've got other alternatives which should be listed here please let me know.

There is also a great thread on stack overflow http://stackoverflow.com/questions/4114083/ios-tests-specs-tdd-bdd-and-integration-acceptance-testing

Extensive description

This library or bundle enables you to do async test operations with asynchronous callbacks in your SenTestCase. Works with GCD (Grand Central Dispatch) and regular delegate callbacks.

Cocoa pods

It's available as AGAsyncTestHelper.

Agens | Digital craftsmanship

About

C Macro's to wait for any async test and get an STFail in your test if it exceeds time limit

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 97.8%
  • Ruby 2.2%