Test Library for Swift's Error Handling

Related tags

Testing CatchingFire
Overview

CatchingFire

License: MIT CocoaPods

CatchingFire is a Swift test framework, which helps making expectations against the error handling of your code. It provides for this purpose two higher-order functions, which take throwing functions and check whether the given closure throws or not. It integrates seamlessly with the expecters provided by XCTest.

Usage

AssertNoThrow

AssertNoThrow allows you to write safe tests for the happy path of failable functions. It helps you to avoid the try! operator in tests.

If you want to test a function, which may fail in general, you may think of using try. But this would mean that you have to declare your test method as throwing, which causes that XCTest doesn't execute the test anymore.

So in consequence, you would usually need to write:

XCTAssertEqual(try! fib(x), 21)

If the expression fails, your whole test suite doesn't execute further and aborts immediately, which is very undesirable, especially on CI, but also for your workflow when you use TDD.

Instead you can write now:

AssertNoThrow {
    XCTAssertEqual(try fib(x), 21)
}

Or alternatively:

AssertNoThrow(try fib(x)).map { (y: Int) in
    XCTAssertEqual(y, 21)
}

If the expression fails, your test fails.

AssertThrow

AssertThrow allows to easily write exhaustive tests for the exception paths of failable functions. It helps you to avoid writing the same boilerplate code over and over again for tests.

If you want to test a function, that it fails for given arguments, you would usually need to write:

do {
    try fib(-1)
    XCTFail("Expected to fail, but did not failed!")
} catch Error.ArgumentMayNotBeNegative {
    // succeed silently
} catch error {
    XCTFail("Failed with a different error than expected!")
}

Instead you can write now:

AssertThrow(Error.ArgumentMayNotBeNegative) {
    try fib(-1)
}

If the expression or closure doesn't throw the expected error, your test fails.

Installation

CatchingFire is available through CocoaPods. To install it, simply add it to your test target in your Podfile:

use_frameworks!
target "AppTest" do
  pod 'CatchingFire'
end

Author

Marius Rackwitz, [email protected]
Find me on Twitter as @mrackwitz.

License

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

You might also like...
Test task application based on Swift using CoreData, Alamofire, AlamofireImage and CocoaPods
Test task application based on Swift using CoreData, Alamofire, AlamofireImage and CocoaPods

iTunes Search Test task application based on Swift using CoreData, Alamofire, AlamofireImage and CocoaPods Features 🔍 Searching music albums by name

test ios UnitTest and UITest

github_actions Bundlerの導入 fastlaneやiOSパッケージマネージャであるCocoaPodsはRubyのライブラリ 開発チームで使用するバージョンを揃えるためにBundlerを導入する bundlerのインストール gem install bundler Gemfile

Test Technique pour LeBonCoin

Test Technique pour LeBonCoin Test Technique pour LeBonCoin Créer une application universelle (iPhone, iPad) en Swift. Celle-ci devra afficher une lis

iOS Test Hasitha

Welcome to the Bidone iOS Coding Test! iOS Create a simple application with the list of orders from viewModel and display them in a list. When a user

iOS Test for Openbank by David Moreno Lora
iOS Test for Openbank by David Moreno Lora

MarvelMobileTest-iOS iOS Test for Openbank by David Moreno Lora Installation Clone the project and install the dependencies using pod install Once th

Trade Me Technical Test
Trade Me Technical Test

TradeMeTechnicalTest Chris Samuels This repository contains a Xcode project. It is for submission to Trade Me Mobile Technical Test. The Application i

Write unit tests which test the layout of a view in multiple configurations
Write unit tests which test the layout of a view in multiple configurations

Overview This library enables you to write unit tests which test the layout of a view in multiple configurations. It tests the view with different dat

iOS UI Automation Test Framework

Deprecation: EarlGrey 1.0 is deprecated in favor of EarlGrey 2.0 which integrates it with XCUITest. Please look at the earlgrey2 branch. EarlGrey 1.0

A collection of useful test helpers designed to ease the burden of writing tests for iOS applications.
A collection of useful test helpers designed to ease the burden of writing tests for iOS applications.

MetovaTestKit is a collection of useful test helpers designed to ease the burden of writing tests for iOS applications. Requirements Installation Usag

Comments
  • Show failures on same line as caller

    Show failures on same line as caller

    Failure messages are now shown on the line that initially used the assertion, not buried in the framework code.

    This is done by setting default file and line parameters to each assertion method. The default for these options are __FILE__ and __LINE__, respectively, which come from Swift's implicitly defined constants. See the image below for an example.

    screen shot 2015-12-27 at 2 04 04 pm

    More information can be found in this blog post, Custom Helpers in XCTest.

    opened by joemasilotti 0
Owner
Marius Rackwitz
Cofounder @nlbb, Developer, Swift Pioneer @CocoaPods Core team, Conference Speaker. Email me to: contact@$firstName$lastName.de
Marius Rackwitz
Kfm-ios-test - Test online for iOS Developer position in Kimia Farma or PT. Buana Varia Komputama

kfm-ios-test Kimia Farma Mobile iOS Test Test online for iOS Developer position

Erwindo Sianipar 3 Feb 23, 2022
The XCTest Project, A Swift core library for providing unit test support

XCTest The XCTest library is designed to provide a common framework for writing unit tests in Swift, for Swift packages and applications. This version

Apple 1k Jan 4, 2023
A Swift test double library. Guava - looks like an apple but it's not.

Guava Guava helps you to make your unit tests more flexible. It allows you to replace parts of your system under test with a test double objects. Tabl

Denis Chagin 10 Mar 22, 2022
Trust - Swift DCI Test Library

Trust Swift - DCI Pattern Test Library Support SPM How to use ? struct User {

gitaek lee 1 Feb 13, 2022
Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!

OHHTTPStubs OHHTTPStubs is a library designed to stub your network requests very easily. It can help you: test your apps with fake network data (stubb

Olivier Halligon 4.9k Dec 29, 2022
BDD Framework and test runner for Swift projects and playgrounds

Spectre Special Executive for Command-line Test Running and Execution. A behavior-driven development (BDD) framework and test runner for Swift project

Kyle Fuller 392 Jan 1, 2023
This repository accompanies Test-Driven Development in Swift: Compile Better Code with XCTest and TDD

Apress Source Code This repository accompanies Test-Driven Development in Swift: Compile Better Code with XCTest and TDD by Gio Lodi (Apress, 2021). D

Apress 57 Jan 1, 2023
This is a simple test app getting data from network to practice a tad bit.

test This is a simple test app getting data from network to practice a tad bit. Start Nothing fancy, no CocoaPods, just clone and run! Architecture Ju

null 1 Oct 9, 2021
Test case project for mackolik

Mackolik - iOS Developer - Test Case Gökhan Mandacı 28 Oct 2021 I developed a two-page app and a general purpose drop down widget for the Mackolik Tes

Gökhan Mandacı 0 Oct 28, 2021
This repo holds the code for Dubizzle & Bayut test App

DubizzleClassified This repo holds the code for Dubizzle & Bayut test App About App This is a simple app which basically fetches item list from the gi

Ghassan 0 Jun 2, 2022