Coder Social home page Coder Social logo

stainless's Introduction

Stainless Build Status

Stainless is a lightweight, flexible, unopinionated testing framework.

Example

describe! stainless {
    before_each {
        // Start up a test.
        let mut stainless = true;
    }

    it "makes organizing tests easy" {
        // Do the test.
        assert!(stainless);
    }

    after_each {
        // End the test.
        stainless = false;
    }

    bench "something simple" (bencher) {
        bencher.iter(|| 2u * 2)
    }

    describe! nesting {
        it "makes it simple to categorize tests" {
            // It even generates submodules!
            assert_eq!(2u, 2u);
        }
    }
}

Expands to (roughly):

mod stainless {
    #[test]
    fn makes_organizing_tests_easy() {
        let mut stainless = true;
        assert!(stainless);
        stainless = false;
    }

    #[bench]
    fn something_simple(bencher: &mut test::Bencher) {
        bencher.iter(|| 2u * 2)
    }

    mod nesting {
        #[test]
        fn makes_it_simple_to_categorize_tests() {
            assert_eq!(2u, 2u);
        }
    }
}

Overview

Stainless exports the describe! syntax extension, which allows you to quickly generate complex testing hierarchies and reduce boilerplate through before_each and after_each.

Stainless currently supports 4 types of subblocks:

  • before_each and after_each,
  • it and failing
  • bench
  • nested describe!

before_each and after_each allow you to group common initialization and teardown for a group of tests into a single block, shortening your tests.

it generates tests which use before_each and after_each. failing does the same, except the generated tests are marked with #[should_fail].

bench allows you to generate benchmarks in the same fashion, though before_each and after_each blocks do not affect bench blocks.

Nested describe! blocks allow you to better organize your tests into small units and gives you granular control over where before_each and after_each apply.

Together, these 4 types of subblocks give you more flexibility and control than the built in testing infrastructure.

License

MIT

stainless's People

Contributors

reem avatar emberian avatar vhbit avatar

Watchers

James Cloos avatar  avatar

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.