Giter Site home page Giter Site logo

xerxesb / shouldly Goto Github PK

View Code? Open in Web Editor NEW

This project forked from whatupdave/shouldly

3.0 2.0 2.0 19.72 MB

Should testing for .net

Home Page: http://snappyco.de/articles/2010-02-02-shouldly

License: Other

Ruby 58.81% Shell 0.01% JavaScript 1.68% CSS 3.65% C 29.68% C++ 0.03% XSLT 0.11% C# 6.02%

shouldly's Introduction

Shouldly

How asserting Should be

This is the old Assert way:

Assert.That(contestant.Points, Is.EqualTo(1337));

For your troubles, you get this message, when it fails:

Expected 1337 but was 0

How it Should be:

contestant.Points.ShouldBe(1337);

Which is just syntax, so far, but check out the message when it fails:

contestant.Points should be 1337 but was 0

It might be easy to underestimate how useful this is. Another example, side by side:

Assert.That(map.IndexOfValue("boo"), Is.EqualTo(2));    // -> Expected 2 but was 1
map.IndexOfValue("boo").ShouldBe(2);                    // -> map.IndexOfValue("boo") should be 2 but was 1

Shouldly uses the variables within the ShouldBe statement to report on errors, which makes diagnosing easier.

Another example, if you compare two collections:

(new[] { 1, 2, 3 }).ShouldBe(new[] { 1, 2, 4 });

and it fails because they're different, it'll show you the differences between the two collections: should be [1, 2, 4] but was [1, 2, 3] difference [1, 2, 3]

If you want to check that a particular call does/does not throw an exception, it's as simple as:

Should.Throw<ArgumentOutOfRangeException>(() => widget.Twist(-1));

Then if it chucks a wobbly, you have access to the exception to help debug what the underlying cause was.

Other Shouldly features:

##Equality
    ShouldBe
    ShouldBeOneOf
    ShouldNotBe
    ShouldNotBeOneOf
    ShouldBeGreaterThan(OrEqualTo)
    ShouldBeLessThan(OrEqualTo)
    ShouldBeOfType<T> - Exact type match
    ShouldBeAssignableTo<T>
    ShouldBeInRange
    ShouldNotBeInRange

##Enumerable
    ShouldBe(optional Tolerance/Ignore order)
    ShouldAllBe(predicate)
    ShouldContain
    ShouldContain(predicate)
    ShouldNotContain
    ShouldNotContain(predicate)
    ShouldBeEmpty
    ShouldNotBeEmpty
    ShouldBeOneOf(params)
    ShouldBeSubsetOf

##String
    ShouldBeCloseTo
    ShouldStartWith
    ShouldEndWith
    ShouldContain
    ShouldNotContain
    ShouldContainWithoutWhitespace
    ShouldMatch
    ShouldBeNullOrEmpty
    ShouldNotBeNullOrEmpty

##Dictionary
    ShouldContainKeyShouldContainKeyAndValue
    ShouldNotContainKey
    ShouldNotContainKeyAndValue

##Exceptions
    Should.Throw<T>(Action)
    Should.NotThrow(Action)

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.