Coder Social home page Coder Social logo

xctestasync's Introduction

XCTestAsync

Deprecated

As of Xcode 6, Apple has created a first-party solution to writing asynchronous tests. See Testing with Xcode

Overview

XCTestAsync is an extension to XCTest for asynchronous testing, and is based on SenTestingKitAsync.

Installation

There are currently two ways to add XCTestAsync to your project:

  • Install with CocoaPods (recommended)
  • Manually copying the source files

CocoaPods

CocoaPods is a dependency manager for Objective-C. To include XCTestAsync into your project with CocoaPods, edit your project's podfile as follows:

target :test, :exclusive => true do
    pod 'XCTestAsync', '~> 1.0'
end

Manually

If you are not using CocoaPods, you can copy over XCTestAsync.h and XCTestAsync.m into your test target. In addition, you will need to add -ObjC to your test target linker flags.

Usage

To use XCTestAsync in your tests, do the following:

  1. Import the header:

    #import <XCTestAsync/XCTestAsync.h>
  2. Add your test method that ends with the suffix Async:

    - (void)testMethodAsync
     {
         // your async code here
     }
  3. Tell XCTestAsync when the test succeeds:

     dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC);
     dispatch_after(popTime, dispatch_get_main_queue(), ^{
         XCAsyncSuccess();
     });

Once your async tests start, XCTestAsync will wait until either a failure occurs (by calling assertions such as XCTFail(…) or XCTAssert(…)) or a success is signalled (by calling XCAsyncSuccess()). If neither of these happen, XCTestAsync will wait indefinitely.

Timeouts

If you expect your async test to run within a specified amount of time, you can specify a time limit by calling XCAsyncFailAfter(timeout, description, …). If a success is not signalled within the time limit, the test will fail after timeout number of seconds.

Additional Reading

xctestasync's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xctestasync's Issues

Podspec issue

Hi,

I really like your implementation of async tests. Is there any reason why the minimum version is 7.0?

Thanks!

async setup?

Any recommendations on how to best handle async setup? I had been using AGAsyncTestHelper to spin the run loop, and block until setup was complete but this seems to conflict with XCTestAsync.

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.