A Swift test double library. Guava - looks like an apple but it's not.

Overview

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.


build Swift 5.x platform version Carthage compatible

Table of Contents

Features

Guava provides several types of test doubles:

  • Stub
  • Spy
  • Fake

Usage

import Guava
import XCTest

protocol Calculator {

    func multiply(_ lhs: Int, _ rhs: Int) -> Int
}

final class CalculatorTestDouble: Calculator {

    let multiplyMethod = TestDoubleFactory<Int>()

    func multiply(_ lhs: Int, _ rhs: Int) -> Int {
        return multiplyMethod.invoke(arguments: [lhs, rhs])
    }
}

final class CalculatorTestCase: XCTestCase {

    func testMultiply() {
        let stubValue = 5
        let calculatorTestDouble = CalculatorTestDouble()

        calculatorTestDouble.multiplyMethod.stub(stubValue)

        let result = calculatorTestDouble.multiply(3, 3)
        XCTAssertEqual(result, stubValue)
    }
}

Documentation

See Documentation section.

Installation

Carthage

Update your Cartfile with:

github "merindorium/Guava"

Swift Package Manager

To use Guava with SPM update your Package.swift.

import PackageDescription

let package = Package(
    name: "ExampleProject",
    dependencies: [
        .package(url: "https://github.com/merindorium/Guava.git", from: "v1.2.0")
    ],
    ...
)

Manual

⚠️ This will install Carthage on your system

You could manually build Guava for iOS and MacOS by using:

  1. make release_tooling
  2. make carthage_build
Comments
  • Update async factories

    Update async factories

    Previous implementation did not take into account the reasoning behind Sendable protocol. This PR fixes possible data races and enforces usage of Sendable and @Sendable.

    opened by Terky 0
  • Add async factories

    Add async factories

    ⚠️ This PR could not be merged before #7

    This PR introduces new entities for testing async methods:

    • AsyncTestDoubleFactory for swapping testable entity with throwing test doubles
    • ThrowingAsyncTestDoubleFactory for swapping testable entity with throwing test doubles And updates existing entities:
    • Stub to support stubbing async methods
    • Spy to support recording calls of async methods
    • Fake to support replacing implementation of async methods
    opened by Terky 0
  • Add throwing TestDoubleFactory

    Add throwing TestDoubleFactory

    This PR introduces new entities for testing throwing methods:

    • ThrowingTestDoubleFactory for swapping testable entity with throwing test doubles And updates existing entities:
    • Stub to support stubbing methods that could throw
    • Spy to support recording calls of a methods that could throw
    • Fake to support replacing implementation of a methods that could throw
    opened by Terky 0
  • guava: Assertion mechanism refactoring

    guava: Assertion mechanism refactoring

    Introduction

    Introduce a new assertion mechanism.

    Motivation

    The current approach lacks flexibility.

    • All assertion logic encapsulated inside the library. The only way to receive assertion results is the FailureReporter entity.
    • It's nearly impossible to integrate Guava with third-party libraries (e.g. Nimble). Lots of assertion logic should be rewritten from the ground up.

    Solution

    • Move all FailureReporter usage to the XCTAssert module except for cases when we need to send fatalFailure with Never as return type.
    • Update all assertion methods to return Result<Void, AssertionFailure> instead of Void.
    • Rename MethodCall to RecordedMethodCall to represent stored Spy invocation calls.
    • Update MethodCall to represent the expected method call during calls assertion.
    • Update Argument.Position to be instantiated from its index in an array of arguments.
    enhancement API Break 
    opened by merindorium 0
  • Entities: Spy arguments storing refactoring

    Entities: Spy arguments storing refactoring

    The current approach of storing call arguments directly in Spy is not flexible enough. This PR adds MethodCall entity that stores call arguments. Now Spy stores an array of method calls. That gives us the ability to count calls out-of-box and now Spy stores all calls instead of the last one.

    API Break 
    opened by merindorium 0
Releases(v2.1.0)
Owner
Denis Chagin
Software Developer
Denis Chagin
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
Test Library for Swift's Error Handling

CatchingFire CatchingFire is a Swift test framework, which helps making expectations against the error handling of your code. It provides for this pur

Marius Rackwitz 75 May 16, 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
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
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

Alexander Zhukov 0 Oct 31, 2021
XCTestExtensions is a Swift extension that provides convenient assertions for writing Unit Test.

XCTestExtensions Features XCTAssertEventually (that convenient assertions for writing Unit Test). Use "XCTAssertEventually", you can write asynchronou

shindyu 22 Dec 1, 2022
Test Flickr API for swift

FlickrSearch Main Features Search and display Flickr photos Display full size photos Zoom in and Zoom out a photo Main Goals: Interact with RESTful Fl

Patrick Lee 0 Dec 11, 2021
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
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
test ios UnitTest and UITest

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

SUGY 0 Nov 3, 2021
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

Charfeddine 0 Nov 3, 2021
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

null 0 Nov 12, 2021
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

David Moreno Lora 0 Nov 16, 2021
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

Chris Samuels 0 Nov 25, 2021
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

LinkedIn 565 Nov 16, 2022