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. javascript获取事件源对象和产生事件的对象

    事件源对象是指event对象,其封装了与事件相关的详细信息,比如按键状态. 获取事件源对象的方法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. ...

  2. python字符串填充(转)

    ljust()方法返回字符串左对齐的字符串长度宽度.填充是通过使用指定的fillchar(默认为空格).如果宽度小于len(s)返回原始字符串.语法 以下是ljust()方法的语法: str.ljus ...

  3. Fragment 实现拍照,相册选图,设置头像功能

    设置不成功,http://bbs.csdn.net/topics/391112964 采纳问题回答:这个是fragment没有收到这个回调,原因不多说了,,,你用你对应的ragment.startAc ...

  4. java 用volatile和不用volatile的区别

    在当前的Java内存模型下,线程可以把变量保存在本地内存(比如机器的寄存器)中,而不是直接在主存中进行读写.这就可能造成一个线程在主存中修改了一个变量的值,而另外一个线程还继续使用它在寄存器中的变量值 ...

  5. 信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:

    问题信息详细: 信息: The APR based Apache Tomcat Native library which allows optimal performance in productio ...

  6. spark开启远程调试

    一.集群环境配置 #调试Master,在master节点的spark-env.sh中添加SPARK_MASTER_OPTS变量 export SPARK_MASTER_OPTS="-Xdeb ...

  7. python之列表【list】

    这里介绍下列表的功能 #切片:列表[a:b],从下标为a开始,到下标为(b-1)的元素 # name = [0,1,2,3,4,5,6,7,8,9] # print(name[1:6]) # # 结果 ...

  8. JAVA知识积累 JSP第一篇【JSP介绍、工作原理、生命周期、语法、指令、行为】

    什么是JSP JSP全名为Java Server Pages,java服务器页面.JSP是一种基于文本的程序,其特点就是HTML和Java代码共同存在! 为什么需要JSP JSP是为了简化Servle ...

  9. discuz回贴通知插件实现-获取邮件内容

    //自定义钩子函数,命名:模块_函数名_output()或模块_函数名() //一个是模块执行完,模板输出前执行.一个是模块执行前 //post_reply_output函数会在所有post操作中都会 ...

  10. PHP-GTK的demo在windows下运行出现的问题

    I am trying to use Firebird 2.5.2.26539 with wamp,When i enable the extensions of firebird in php: - ...