Skip to content

futuredapp/FTTestingKit

Repository files navigation

FTTestingKit logo

FTTestingKit

Cocoapods Cocoapods platforms Cocoapods

A set of helpers for simple creation of mockups, random values and testing of asynchronous code.

Installation

When using Swift package manager add this line to your dependencies or install using Xcode 11 or newer:

.package(url: "https://github.com/futuredapp/FTTestingKit.git", from: "0.5.0")

When using CocoaPods add following line to your Podfile:

pod 'FTTestingKit', '~> 0.5'

When using PromiseKit you can use either FTTestingKitPromiseKit target for testing promises or add subspec to your Podfile:

pod 'FTTestingKit', '~> 0.5', subspecs: ['PromiseKit']

Features

Main features of this library are generating mockups, random values, arrays and asynchronous testing.

Mockups

For simple repeated execution the library offers Ruby-like extension on Int type. This is helpful in measurement tests.

10.times {
    doSomething()
}
10.times(doSomething)

This extension can create arrays too:

10.times {
    Int.random()
}
10.times(String.random)

The framework extends some basic types (Date, String) with random generation similar to Int. All these types conform to Mockup protocol which formally describes this functionality.

Date.random()
String.random()
Int.random(count: 10)

Expectations

The framework extends XCTestCase with simple methods to call transactional asynchronous test like this:

expect(within: 0.5) { reply in
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
        reply(.success)
    }
}

Extension for PromiseKit builds on this and offers testing promises using so-called belief in promise method:

believe(for: 0.5, in: someFunctionReturningPromise())

Author

Matěj Kašpar Jirásek, matej.jirasek@futured.app

License

FTTestingKit is available under the MIT license. See the LICENSE file for more info.