A simple and lightweight matching library for XCTest framework.

Overview

Match

A simple and lightweight matching library for XCTest framework.

Getting started

Swift Package Manager

You can add Match to your project by adding it as a dependency in your Package.swift file:

// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyProject",
    products: [
        .library(name: "MyProject", targets: ["MyProject"])
    ],
    dependencies: [
         .package(url: "https://github.com/mtynior/Match.git", .upToNextMajor(from: "0.5.0")),
    ],
    targets: [
        .target(name: "MyProject", dependencies: []),
        .testTarget(name: "MyProject", dependencies: ["Match"])
    ]
)

Xcode

Open your project in Xcode, then:

  1. Click File -> Add Packages,
  2. In the search bar type: https://github.com/mtynior/match.git and press Enter,
  3. Once Xcode finds the library, set Dependency rule to Up to next major version,
  4. Click Add Package,
  5. Select the Test Target (If you have multiple test targets, you can add the dependency manually from Xcode )
  6. Confirm selection by clicking on Add Package.

Writing tests

Now, when we have library integrated with our project, let's write some tests.

Imagine that we have a function that adds two numbers:

func sum(_ a: Int, _ b: Int) -> Int {
    a + b
}

Not we can test our function using XCTest Framework and the Match:

import XCTest
import Match
@testable MyProject

final class SumTests: XCTestCase {
    func testAddingTwoNumbers() {
        // given
        let expectedValue = 5
        
        // when
        let actualValue = sum(2, 3)

        // then
        expect(actualValue).toBeEqual(expectedValue) // Passes: "Expected: 5 is equal to received: 5"
    }
}

If we implemented the sum function correctly the test above will pass.

But let's see what will happen when we make a mistake in the sum implementation:

func sum(_ a: Int, _ b: Int) -> Int {
    a * b
}

Now, our test should fail:

import XCTest
import Match
@testable MyProject

final class SumTests: XCTestCase {
    func testAddingTwoNumbers() {
        // given
        let expectedValue = 5 
        
        // when
        let actualValue = sum(2, 3)

        // then
        expect(actualValue).toBeEqual(expectedValue) // Fails: "Expected: 5 to be equal to received: 6"
    }
}

That's it. Now, check how to use the rest of the Matchers and start testig.

Credits

Icon is made by Freepik and was available at FlatIcon.

License

Match is released under the MIT license. See LICENSE for details.

You might also like...
The Swift (and Objective-C) testing framework.
The Swift (and Objective-C) testing framework.

Quick is a behavior-driven development framework for Swift and Objective-C. Inspired by RSpec, Specta, and Ginkgo. // Swift import Quick import Nimbl

Switchboard - easy and super light weight A/B testing for your mobile iPhone or android app. This mobile A/B testing framework allows you with minimal servers to run large amounts of mobile users.

Switchboard - easy A/B testing for your mobile app What it does Switchboard is a simple way to remote control your mobile application even after you'v

Remote configuration and A/B Testing framework for iOS

MSActiveConfig v1.0.1 Remote configuration and A/B Testing framework for iOS. Documentation available online. MSActiveConfig at a glance One of the bi

AutoMocker is a Swift framework that leverages the type system to let you easily create mocked instances of your data types.

AutoMocker Context AutoMocker is a Swift framework that leverages the type system to let you easily create mocked instances of your data types. Here's

Boilerplate-free mocking framework for Swift!

Cuckoo Mock your Swift objects! Introduction Cuckoo was created due to lack of a proper Swift mocking framework. We built the DSL to be very similar t

Mockit is a Tasty mocking framework for unit tests in Swift 5.0
Mockit is a Tasty mocking framework for unit tests in Swift 5.0

Mockit Introduction Mockit is a Tasty mocking framework for unit tests in Swift 5.0. It's at an early stage of development, but its current features a

BDD-style framework for Swift
BDD-style framework for Swift

Sleipnir Sleipnir is a BDD-style framework for Swift. Sleipnir is highly inspired by Cedar. Also In Norse mythology, Sleipnir is Odin's steed, is the

A convenient mocking framework for Swift
A convenient mocking framework for Swift

// Mocking let bird = mock(Bird.self) // Stubbing given(bird.getName()).willReturn("Ryan") // Verification verify(bird.fly()).wasCalled() What is Mo

A mocking framework for Swift

SwiftMock SwiftMock is a mocking framework for Swift 5.2. Notes on the history of this repo September 2015: first version of this framework November 2

Owner
Michał Tynior
My name is Michal Tynior and I am a software engineer, iOS developer, consultant, and trouble maker in general.
Michał Tynior
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
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
Assertions for XCTest which prevent fatal errors causing the process to die.

Hela Assertions for XCTest which prevent fatal errors causing the process to die. The following assertions are supported. These functions are built on

Brennan Stehling 3 Nov 7, 2022
XCTestCrashDemo - XCTest Crash Demo with swift

XCTest Crash Demo This repo intends to centralize XCTest crash errors and the wa

Omar Zúñiga 0 Jan 3, 2022
Lightweight touch visualization library in Swift. A single line of code and visualize your touches!

TouchVisualizer is a lightweight pure Swift implementation for visualising touches on the screen. Features Works with just a single line of code! Supp

Morita Naoki 851 Dec 17, 2022
T - A simple testing framework using closures and errors

t Quickly test expectations What is t? t is a simple testing framework using clo

OpenBytes 6 Nov 7, 2022
PinpointKit is an open-source iOS library in Swift that lets your testers and users send feedback with annotated screenshots using a simple gesture.

PinpointKit is an open-source iOS library in Swift that lets your testers and users send feedback with annotated screenshots using a simple gesture. F

Lickability 1.1k Jan 6, 2023
Basic (simple) App for MacOS with simple functionality

Test Mac App Basic (simple) App for MacOS with simple functionality General Details Build : 1.0 Author Alias : gonewithharshwinds Brand : ADV Descript

Harsh ADV) 1 Dec 25, 2021
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
A Matcher Framework for Swift and Objective-C

Nimble Use Nimble to express the expected outcomes of Swift or Objective-C expressions. Inspired by Cedar. // Swift expect(1 + 1).to(equal(2)) expect(

Quick 4.6k Dec 31, 2022