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. localstorage是什么,它有哪些作用

    localStorage作为HTML5本地存储web storage特性的API之一,主要作用是将数据保存在客户端中,而客户端一般是指上海网站设计用户的计算机.在移动设备上,由于大部分浏览器都支持 w ...

  2. FastDFSClient工具类 文件上传下载

    package cn.itcast.fastdfs.cliennt; import org.csource.common.NameValuePair; import org.csource.fastd ...

  3. mac安装protobuf2.4.1时报错./include/gtest/internal/gtest-port.h:428:10: fatal error: 'tr1/tuple' file not found和google/protobuf/message.cc:175:16: error: implicit instantiation of undefined template

    通过网上下载的protobuf2.4.1的压缩文件,然后进行安装,./configure和make时遇到了两个问题. 正常的安装步骤如下: ./configure make  make check m ...

  4. ubuntu连有线网 无法连接外网

    问题:连上网线后,有ip,但是无法访问外网. 我的解决方案是: .通过命令行ifconfig命令查看以太网(即网线插口)的名称,如下图,'enp3s0'是网线插口(Ethernet以太网): zhum ...

  5. TZOJ 1242 求出前m大的数(预处理)

    描述 给定一个包含N(N<=3000)个正整数的序列,每个数不超过5000,对它们两两相加得到的N*(N-1)/2个和,求出其中前M大的数(M<=10000)并按从大到小的顺序排列. 输入 ...

  6. python进程之间修改数据[Manager]与进程池[Pool]

    #前面的队列Queue和管道Pipe都是仅仅能再进程之间传递数据,但是不能修改数据,今天我们学习的东西就可以在进程之间同时修改一份数据 #Mnager就可以实现 import multiprocess ...

  7. Swift 项目中可能用到的第三方框架

    这里记录下swift开发中可能用的框架 , 最近浏览了不少,积累在这里,以后用的时候方便查阅.顺便推荐给大家! 这里的框架都是纯swift的 , 感谢开源 ,感谢大神们 . 下拉刷新 BreakOut ...

  8. dede后台一片空白

    原因是你修改了后台的数据库连接信息文件data/common.inc.php,保存的后文件编码并不是utf-8,而是变成了ANSI或utf-8 + bom的. 解决方法: 用editplus或note ...

  9. Spring框架的事务管理的分类

    1. Spring的事务管理的分类 1. Spring的编程式事务管理(不推荐使用) * 通过手动编写代码的方式完成事务的管理(不推荐) 2. Spring的声明式事务管理(底层采用AOP的技术) * ...

  10. Adplus 抓取Crash Dump

    本实例在win8.1 安装window kits https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit 1 ...