Code Monkey home page Code Monkey logo

tablier's Introduction

Tablier

Build Status codecov Swift 5 CocoaPods compatible Carthage compatible SPM compatible Supports iOS, macOS, tvOS and Linux MIT License

A micro-framework for Table Driven Tests.

A screenshot to see how it works

Features

  • ☑️ Dead simple syntax
  • ☑️ Run sync and async tests in parallel
  • ☑️ No additional dependency aside from XCTest
  • ☑️ Use with Quick, or any other XCTest-based testing frameworks
  • ☑️ Fully tested itself

Installation

Swift Package Manager

.package(url: "https://github.com/akkyie/Tablier", from: <#version#>)

Cocoapods

target 'YourTests' do
    inherit! :search_paths
    pod 'Tablier'
end

Usage

Synchronous Recipe

You can define a test recipe to test your classes, structs or functions.

final class MyParseTests: XCTestCase {
    func testMyParse() {
        let recipe = Recipe<String, Int>(sync: { input in
            // `myParse` here is what you want to test
            let output: Int = try myParse(input) // it fails if an error is thrown
            return output
        })
...

Then you can list inputs and expected outputs for the recipe, to run the actual test for it.

...
        recipe.assert(with: self) {
            $0.when("1").expect(1)
            $0.when("1234567890").expect(1234567890)
            $0.when("-0x42").expect(-0x42)
        }
    }
}

Asynchronous Recipe

Defining a recipe with an asynchronous completion is also supported.

let recipe = Recipe<String, Int>(async: { input, complete in
    myComplexAndSlowParse(input) { (result: Int?, error: Error?) in
        complete(result, error)
    }
})

Since Swift 5.5, you can use AsyncRecipe to define asynchronous recipes with async/await syntax:

let recipe = AsyncRecipe<String, Int> { input in
    try await myComplexAndSlowParse(input)
}

Note

Note

When an error is thrown in the sync initalizer or the completion handler is called with an error, the test case is considered as failed for now. Testing errors will be supported in the future.

Examples

License

MIT. See LICENSE.

tablier's People

Contributors

akkyie avatar dekatotoro avatar

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

Watchers

 avatar  avatar  avatar

Forkers

abema

tablier's Issues

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.