All Projects β†’ onmyway133 β†’ Spek

onmyway133 / Spek

Licence: other
🎏 Function builder BDD testing framework in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Spek

Expekt
BDD assertion library for Kotlin
Stars: ✭ 163 (+56.73%)
Mutual labels:  test, bdd
Shellspec
A full-featured BDD unit testing framework for bash, ksh, zsh, dash and all POSIX shells
Stars: ✭ 375 (+260.58%)
Mutual labels:  test, bdd
Nightwatch Cucumber
[DEPRECATED] Cucumber.js plugin for Nightwatch.js.
Stars: ✭ 243 (+133.65%)
Mutual labels:  test, bdd
Fluentdocker
Commands, Services and Fluent API for docker, docker-compose & docker-machine, for win/mac/linux and native docker in c#
Stars: ✭ 245 (+135.58%)
Mutual labels:  builder, test
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+765.38%)
Mutual labels:  test, bdd
Should.js
BDD style assertions for node.js -- test framework agnostic
Stars: ✭ 1,908 (+1734.62%)
Mutual labels:  test, bdd
bdd-for-c
A simple BDD library for the C language
Stars: ✭ 90 (-13.46%)
Mutual labels:  test, bdd
Snap Shot It
Smarter snapshot utility for Mocha and BDD test runners + data-driven testing!
Stars: ✭ 138 (+32.69%)
Mutual labels:  test, bdd
Specs2
Software Specifications for Scala
Stars: ✭ 696 (+569.23%)
Mutual labels:  test, bdd
Ginkgo
BDD Testing Framework for Go
Stars: ✭ 5,346 (+5040.38%)
Mutual labels:  test, bdd
Mocha
β˜•οΈ simple, flexible, fun javascript test framework for node.js & the browser
Stars: ✭ 20,986 (+20078.85%)
Mutual labels:  test, bdd
Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (-60.58%)
Mutual labels:  test, bdd
Chakram
REST API test framework. BDD and exploits promises
Stars: ✭ 912 (+776.92%)
Mutual labels:  test, bdd
Kahlan
βœ”οΈ PHP Test Framework for Freedom, Truth, and Justice
Stars: ✭ 1,065 (+924.04%)
Mutual labels:  test, bdd
Ngx Dynamic Form Builder
FormBuilder + class-transformer + class-validator = dynamic form group builder for Angular10+
Stars: ✭ 93 (-10.58%)
Mutual labels:  builder
Func Loc
A simple tool that helps you to retrieve the function location from its reference.
Stars: ✭ 99 (-4.81%)
Mutual labels:  function
React Pinpoint
An open source utility library for measuring React component render times.
Stars: ✭ 93 (-10.58%)
Mutual labels:  test
Tars Cli
CLI for TARS
Stars: ✭ 92 (-11.54%)
Mutual labels:  builder
Dd
Binary Decision Diagrams (BDDs) in pure Python and Cython wrappers of CUDD, Sylvan, and BuDDy
Stars: ✭ 102 (-1.92%)
Mutual labels:  bdd
Scram
Probabilistic Risk Analysis Tool (fault tree analysis, event tree analysis, etc.)
Stars: ✭ 98 (-5.77%)
Mutual labels:  bdd

Spek

❀️ Support my app ❀️

β€οΈβ€οΈπŸ˜‡πŸ˜πŸ€˜β€οΈβ€οΈ

Spek is a lightweight function builder style Behavior Driven Development framework, designed to be used with XCTest

Usage

⚠️Before using any test frameworks, you need to ensure there is XCTest framework in your test target.

import XCTest
@testable import Spek

final class SpekTests: XCTestCase {
    func testExample() {
        var left = 1
        var right = 1

        spec {
            Describe("math") {
                BeforeEach {
                    left = 2
                }

                Describe("basic") {
                    BeforeEach {
                        right = 3
                    }

                    AfterEach {

                    }

                    It("adds correctly") {
                        XCTAssertEqual(left + right, 5)
                    }

                    It("multiplies correctly") {
                        XCTAssertEqual(left * right, 6)
                    }
                }
            }
        }
    }
}

Features

  • Support common BDD parts: Describe, Context, BeforeAll, AfterAll, BeforeEach, AfterEach, It
  • To disable a part, prefix it with X, for example XDescribe, XIt, ...
  • All blocks are throwing function, so are encouraged to do try catch
  • BeforeAll and AfterAll are run before and after all enclosing Describe and It
  • BeforeEach and AfterEach are run before and after all enclosing It
  • Context behaves the same as Describe

How to

Disable a block

When you have an imcomplete block, instead of commenting it out, you can prefix it with X so it won't be executed

Describe("math") {
    It("will be run") {

    }

    XIt("won't be run") {

    }
}

Declare local variables

Spek uses Swift 5.1 function builder so you can only declare block and nested block. To declare local variables in a subspec, you need to use Sub and return Describe explicitly

Describe("math") {
    Describe("advanced") {

    }

    Sub {
        let abc = 1
        let def = 2
        return Describe("extra") {
            It("should add") {
                XCTAssertEqual(abc + def, 2)
            }
        }
    }
}

Generate XCTestCase

By default, spec method runs the test directly, to generate test cases, you need to override makeDescribe.

Subclass SpekTestCase and override makeDescribe method, Spek will convert your Describe descriptions and generate XCTestCase methods. It generates test methods for nested Describe and Sub too.

For example the below test will generate test_math_should_work and test_math_advanced_should_calculate methods

import XCTest
import Spek

class GenerateTestCaseTests: SpekTestCase {
    override class func describe() -> Describe {
        Describe("math") {
            It("should work") {
                XCTAssertTrue(1 + 1 == 2)
            }

            Describe("advanced") {
                It("should calculate") {
                    XCTAssertEqual(2 * 5, 10)
                }
            }
        }
    }
}

Install

Spek is distributed using the Swift Package Manager. To install it into a project, add it as a dependency within your Package.swift manifest:

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/onmyway133/Spek.git", from: "0.5.0")
    ],
    ...
)

Then import Spek in your XCTest

import Spek

Author

Khoa Pham, [email protected]

Credit

  • Quick for testInvocations reference

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].