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. Pandas缺失数据处理

    Pandas缺失数据处理 Pandas用np.nan代表缺失数据 reindex() 可以修改 索引,会返回一个数据的副本: df1 = df.reindex(index=dates[0:4], co ...

  2. console.log等不能打印全部数据/信息

    有时候console.log在chrome调试控制台打印不全,如下: 这个时候,我们可以点击进去:用watch 工具,添加变量,右击copy value 选项:

  3. centos7 /etc/profile /etc/bashrc

    在/etc/profile中添加环境变量后,是使用source /etc/profile编译后只能在当前终端生效 重新开启一个终端后,该环境变量失效. 解决方法: 重启系统:reboot,问题解决 环 ...

  4. Maven 基础配置

    pom.xml基础配置: maven中,最让我迷惑的还是那一堆配置! 就拿这个属性配置来说: <properties> <project.build.sourceEncoding&g ...

  5. SpringMVC上传文件的MultipartFile源码

    零.MultipartFile上传文件的具体实例如下: http://blog.csdn.net/swingpyzf/article/details/20230865 一.具体类和方法 上传文件主要方 ...

  6. POJ1950----DFS

    Dessert Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6193   Accepted: 2299 Descripti ...

  7. Super Star(最小球覆盖)

    Super Star http://poj.org/problem?id=2069 Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  8. PTA 习题集5-18 打印选课学生名单(哈希)

    假设全校有最多40000名学生和最多2500门课程.现给出每个学生的选课清单,要求输出每门课的选课学生名单. 输入格式: 输入的第一行是两个正整数:N(≤40000),为全校学生总数:K(≤2500) ...

  9. python作业之用户管理程序

    数据库的格式化如下 分别为姓名|密码|电话号码|邮箱|用户类型 admin|admin123.|28812341026|admin@126.com|1root|admin123.|1344566348 ...

  10. win10下zip安装mysql5.7的一些问题

    一.MySQL下载地址: http://dev.mysql.com/downloads/mysql/ 我们下载zip版本的   二.解压zip文件   三.复制一份里面的my-default.ini为 ...