Should Assertion Library,通常在测试时用到,可以与nunit 结合使用。

已经从codeplex 迁移到 github。网址如下

https://github.com/erichexter/Should

github 时常访问不了,这次能访问,主要内容先摘抄记录下,备查询。

Project Description

The Should Assertion Library provides a set of extension methods for test assertions for AAA and BDD style tests. It provides assertions only, and as a result it is Test runner agnostic. The assertions are a direct fork of the xUnit test assertions. This project was born because test runners Should be independent of the the assertions!

Should Assertion Library comes in two flavors, each with it's own binary.

Standard

Install from nuget.

PM> install-package should

The following example shows some of the assertions that are available for objects, booleans, string, and collections.

public void Should_assertions()
{
object obj = null;
obj.ShouldBeNull(); obj = new object();
obj.ShouldBeType(typeof(object));
obj.ShouldEqual(obj);
obj.ShouldNotBeNull();
obj.ShouldNotBeSameAs(new object());
obj.ShouldNotBeType(typeof(string));
obj.ShouldNotEqual("foo"); obj = "x";
obj.ShouldNotBeInRange("y", "z");
obj.ShouldBeInRange("a", "z");
obj.ShouldBeSameAs("x"); "This String".ShouldContain("This");
"This String".ShouldNotBeEmpty();
"This String".ShouldNotContain("foobar"); false.ShouldBeFalse();
true.ShouldBeTrue(); var list = new List<object>();
list.ShouldBeEmpty();
list.ShouldNotContain(new object()); var item = new object();
list.Add(item);
list.ShouldNotBeEmpty();
list.ShouldContain(item);
}

Fluent

Should.Fluent is a direct port of ShouldIt. Install from nuget.

PM> install-package ShouldFluent

The following shows the same assertions as above but in the fluent style.

public void Should_fluent_assertions()
{
object obj = null;
obj.Should().Be.Null(); obj = new object();
obj.Should().Be.OfType(typeof(object));
obj.Should().Equal(obj);
obj.Should().Not.Be.Null();
obj.Should().Not.Be.SameAs(new object());
obj.Should().Not.Be.OfType<string>();
obj.Should().Not.Equal("foo"); obj = "x";
obj.Should().Not.Be.InRange("y", "z");
obj.Should().Be.InRange("a", "z");
obj.Should().Be.SameAs("x"); "This String".Should().Contain("This");
"This String".Should().Not.Be.Empty();
"This String".Should().Not.Contain("foobar"); false.Should().Be.False();
true.Should().Be.True(); var list = new List<object>();
list.Should().Count.Zero();
list.Should().Not.Contain.Item(new object()); var item = new object();
list.Add(item);
list.Should().Not.Be.Empty();
list.Should().Contain.Item(item);
};

Here are some additional examples of assertions using the fluent API:

public void Should_fluent_assertions()
{
var numbers = new List<int> { , , , };
numbers.Should().Contain.Any(x => x == );
numbers
.Should().Count.AtLeast()
.Should().Count.NoMoreThan()
.Should().Count.Exactly()
.Should().Contain.One(x => x > ); var id = new Guid();
id.Should().Be.Empty(); id = Guid.NewGuid();
id.Should().Not.Be.Empty(); var date = DateTime.Now;
date1.Should().Be.Today(); var str = "";
str.Should().Be.NullOrEmpty(); var one = "";
one.Should().Be.ConvertableTo<int>(); var idString = Guid.NewGuid().ToString();
idString.Should().Be.ConvertableTo<Guid>();
}

Should Assertion Library的更多相关文章

  1. Unity 5.1+ Assertion Library (断言库)

    Unity 5.1+ ,加入了“断言库”,在 Asset 类中可以方便的找到需要使用断言的函数. UnityEngine.Assertions.Assert.IsNotNull( ) 为何使用断言 使 ...

  2. [React Testing] JSX error diffs -- expect-jsx library

    When writing React component tests, it can be hard to decipher the error diffs of broken tests, sinc ...

  3. Reactor by Example--转

    原文地址:https://www.infoq.com/articles/reactor-by-example Key takeaways Reactor is a reactive streams l ...

  4. A Complete List of .NET Open Source Developer Projects

    http://scottge.net/2015/07/08/a-complete-list-of-net-open-source-developer-projects/?utm_source=tuic ...

  5. JavaScript测试工具比较: QUnit, Jasmine, and Mocha

    1. QUnit A JavaScript Unit Testing framework. QUnit is a powerful, easy-to-use JavaScript unit testi ...

  6. 关于JavaScript测试工具:QUnit, Jasmine, MoCha

    在进行前端开发过程中,在某些场景下,需要通过编写单元测试来提高代码质量.而JavaScript常用的单元测试框架有这几个:QUnit, Jasmine, MoCha.下面就基于这三个工具,简单做一比较 ...

  7. Top JavaScript Frameworks, Libraries & Tools and When to Use Them

    It seems almost every other week there is a new JavaScript library taking the web community by storm ...

  8. 全栈式JavaScript

    如今,在创建一个Web应用的过程中,你需要做出许多架构方面的决策.当然,你会希望做的每一个决定都是正确的:你想要使用能够快速开发的技术,支持持续的迭代,最高的工作效率,迅速,健壮性强.你想要精益求精并 ...

  9. Web Development Terms

    I've come across lots of terms while learning web development. I'm feeling myself overwhelmed. Here ...

随机推荐

  1. 如何将Wav文件做到EXE文件里

    1)编写.RC文件 ..RC文件是资源的源文件,编译器也就编译这个文件,生成.RES的资源文件 首先在我们的项目子目录中建立一个纯文本文件,起名叫Sound.rc,文件中 有一行,内容为: SOUND ...

  2. python 的None 探究

    a = None b = None print id(a),id(b),id(None) # 9430224 9430224 9430224 可能在别的环境下运行不是这个数,但是这三个数应该是一样的. ...

  3. neo4j 学习-1

    Neo4j 子句 ```MATCH (:Person { name: 'an' })-[r]->(:Persion) RETURN type(r) // 返回关系的类型 如:r 就是 'KNOW ...

  4. one by one 项目 part 5

    问题汇总 一.Can't connect to MySQL server on 'localhost' (10061)翻译:不能连接到 localhost 上的mysql分析:这说明“localhos ...

  5. blast及其格式输出简介

    1)blast产生背景 双序列比对可以采用是基于动态规划算法的Needleman-Wunsch(NW)和Smith-Waterman algorithm(SW)算法,虽然精度高,但计算消耗大.当与数据 ...

  6. Java的反射和代理以及注解

    最近接触到java的反射和代理(接触的有点迟了...),还是有必要总结下 1. Java的反射 有的时候我们需要在程序运行的时候获取类.方法等信息用于动态运行,这个时候反射就能够帮我们找到类.方法.成 ...

  7. JS中如何处理多个ajax并发请求?

    js中的多并发处理. 通常 为了减少页面加载时间,先把核心内容显示处理,页面加载完成后再发送ajax请求获取其他数据 这时就可能产生多个ajax请求,为了用户体验,最好是发送并行请求,这就产生了并发问 ...

  8. 数据库事务(Database Transaction)

    事务(Transaction)是访问并可能更新数据库中各种数据项的一个程序执行单元(unit).事务由事务开始(begin transaction)和事务结束(commit transaction或 ...

  9. [leetcode]523. Continuous Subarray Sum连续子数组和(为K的倍数)

    Given a list of non-negative numbers and a target integer k, write a function to check if the array ...

  10. [leetcode]340. Longest Substring with At Most K Distinct Characters至多包含K种字符的最长子串

    Given a string, find the length of the longest substring T that contains at most k distinct characte ...