Giter Site home page Giter Site logo

expecto.testapi's Introduction

Expecto.TestApi

Test API

Test API is a Behavior Driven Development pattern developed by Paul Spoon.

The key idea is that test own their own dependency abstractions (e.g. interfaces) like any other service would. This decouples the test from the system, and the difference is bridge with adapters. Key advantages include

  • The tests focus on encoding requirements, not accommodating the system
  • The tests don't change when the system changes, only when requirements change
  • The tests are clean, no matter how messy the system is
  • The same tests can be reused for multiple configurations (i.e. as unit test and as any combination of integrated components)

This Library

This library is a extension of Expecto to enable simple definition of tests against an abstraction, and compose those tests in lists with normal Expecto tests. It takes care of the tricky bits for managing environment lifetimes, especially with property tests.

This library is pretty early in development. Everything that's in place should function well (mostly work is passed to Expecto), but

  • not all test functions have been wrapped yet
  • names and signatures are subject to change as I learn more

Example

Here's a normal test list with Expecto

testList [
    test "Name" (fun () -> )
    test "More Name" (fun () -> )
    testProperty "Name here" (fun other args ->)
    //...
]

The testApi version uses a reader monad to keep the definition very similar

let testEnv = {
    setup () = 
        //...
        (api, env) // separates public interface from internal state
    cleanup env = 
        //...
}

testListWithEnv [
    testWithEnv "Name" (fun api -> )
    testWithEnv "More Name" (fun api -> )
    testPropertyWithEnv "Name here" (fun api (other, args) ->)
    //...
] testEnv

IMPORTANT: If a property test has more than one parameter, they must be bundled into a tuple. It looks about the same and behaves the same as one would expect. However, it is necessary to circumvent unknown arity issues (unknown number of arguments).

Design reasoning

Key realizations that made this library possible are described on my blog

expecto.testapi's People

Contributors

farlee2121 avatar

Stargazers

Dima Vlasov avatar Andrii Chebukin avatar

Watchers

James Cloos avatar  avatar

Forkers

willehrendreich

expecto.testapi'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.