Latest 1.4.1
Homepage https://github.com/seivan/SHTestCaseAdditions
License MIT
Authors

Build Status
Version
Platform

Overview

Prefixed Asynchronous test helpers as a category on SenTestCase and XCTestCase

  • Swizzle and junk free
  • Prefixed selectors.
  • Works with both SentTest (Xcode 4) and XCTest (Xcode 5)
  • For iOS and Mac OS
  • Comes with tests and example.

Navigation

API

Usage

Installation

Default is for XCTest

pod 'SHTestCaseAdditions'
pod 'SHTestCaseAdditions/XCTest'

For SenTestKit

pod 'SHTestCaseAdditions/SenTestKit'

Setup

Put this either in specific files or your project prefix file

XCTestCase

#import <XCTestCase+SHTestCaseAdditions.h>

SenTestKit

#import <SenTestCase+SHTestCaseAdditions.h>

or

#import "SHTestCaseAdditions.h"

API


#pragma mark -
#pragma mark Block Definitions
typedef BOOL (^SHTestCaseConditional)();
typedef void (^SHTestCaseBlock)(BOOL *didFinish);

#pragma mark -
#pragma mark Helpers
-(void)SH_waitForTimeInterval:(NSTimeInterval)theTimeInterval;

-(void)SH_runLoopUntilTestPassesWithBlock:(SHTestCaseConditional)theBlock
                              withTimeOut:(NSTimeInterval)theTimeout;

-(void)SH_performAsyncTestsWithinBlock:(SHTestCaseBlock)theBlock
                           withTimeout:(NSTimeInterval)theTimeout;

@end

Usage


-(void)testSH_waitForTimeInterval; {
  __block BOOL assertion = NO;

  double delayInSeconds = 5.0;
  dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    assertion = YES;
  });

  [self SH_waitForTimeInterval:delayInSeconds];
  XCTAssertTrue(assertion);
}

-(void)testSH_runLoopUntilTestPassesWithBlock_withTimeOut; {
  NSString * keyPath   = @"sampleSet";
  __block BOOL didPass = NO;

  [self SH_addObserverForKeyPaths:@[keyPath] withOptions:0 block:^(id weakSelf, NSString *keyPath, NSDictionary *change) {
    didPass = YES;
  }];

  double delayInSeconds = 2;
  dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [[self mutableArrayValueForKey:keyPath] addObject:@"Lol"];
  });

  [self SH_runLoopUntilTestPassesWithBlock:^BOOL{
    return didPass;
  } withTimeOut:5];

  XCTAssertTrue(didPass);

}

-(void)testSH_performAsyncTestsWithinBlock_withTimeout; {
  NSString * keyPath   = @"sampleArray";
  __block BOOL didPass = NO;

  [self SH_performAsyncTestsWithinBlock:^(BOOL *didFinish) {

    [self SH_addObserverForKeyPaths:@[keyPath] withOptions:0 block:^(id weakSelf, NSString *keyPath, NSDictionary *change) {
      didPass    = YES;
      *didFinish = YES;
    }];

    double delayInSeconds = 2;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
      [[self mutableArrayValueForKey:keyPath] addObject:@"Lol"];
    });

  } withTimeout:5];

  XCTAssertTrue(didPass);

}

Contact

If you end up using SHTestCaseAdditions in a project, I’d love to hear about it.

email: [email protected]
twitter: @seivanheidari

License

SHTestCaseAdditions is © 2013 Seivan and may be freely
distributed under the MIT license.
See the LICENSE.md file.

Latest podspec

{
    "name": "SHTestCaseAdditions",
    "version": "1.4.1",
    "summary": "Prefixed category on SenTestCase and XCTestCase to help with asynchronous callbacks. SenTestKit: SHTestCaseAdditions/SenTestCase",
    "description": "  n  SHTestCaseAdditions contains asynchronous helpers (as a prefixed category) to write tests in SentTest and/or XCTest for delayed callbacks, n  like network calls or alert views, action sheets. Prefixed category on SenTestCase and XCTestCasenn                    * Swizzle and junk freen                    * Prefixed selectors.n                    * Works with both SentTest and/or XCTestn                    * For iOS and Mac OSn                    * Comes with tests and example. n                    n",
    "homepage": "https://github.com/seivan/SHTestCaseAdditions",
    "license": "MIT",
    "authors": {
        "Seivan Heidari": "[email protected]"
    },
    "source": {
        "git": "https://github.com/seivan/SHTestCaseAdditions.git",
        "tag": "1.4.1"
    },
    "default_subspec": "XCTest",
    "requires_arc": true,
    "subspecs": [
        {
            "name": "XCTest",
            "frameworks": [
                "XCTest"
            ],
            "source_files": [
                "SHTestCaseAdditions/*.{h,m}",
                "SHTestCaseAdditions/XCTest/*.{h,m}"
            ]
        },
        {
            "name": "SenTestingKit",
            "frameworks": [
                "SenTestingKit"
            ],
            "source_files": [
                "SHTestCaseAdditions/*.{h,m}",
                "SHTestCaseAdditions/SenTestingKit/*.{h,m}"
            ]
        }
    ]
}

Pin It on Pinterest

Share This