Should Assertion Library
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 (Should.dll)
Fluent (Should.Fluent.dll)
Use our prerelease nuget feed: http://www.myget.org/F/should/
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的更多相关文章
- Unity 5.1+ Assertion Library (断言库)
Unity 5.1+ ,加入了“断言库”,在 Asset 类中可以方便的找到需要使用断言的函数. UnityEngine.Assertions.Assert.IsNotNull( ) 为何使用断言 使 ...
- [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 ...
- Reactor by Example--转
原文地址:https://www.infoq.com/articles/reactor-by-example Key takeaways Reactor is a reactive streams l ...
- 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 ...
- JavaScript测试工具比较: QUnit, Jasmine, and Mocha
1. QUnit A JavaScript Unit Testing framework. QUnit is a powerful, easy-to-use JavaScript unit testi ...
- 关于JavaScript测试工具:QUnit, Jasmine, MoCha
在进行前端开发过程中,在某些场景下,需要通过编写单元测试来提高代码质量.而JavaScript常用的单元测试框架有这几个:QUnit, Jasmine, MoCha.下面就基于这三个工具,简单做一比较 ...
- 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 ...
- 全栈式JavaScript
如今,在创建一个Web应用的过程中,你需要做出许多架构方面的决策.当然,你会希望做的每一个决定都是正确的:你想要使用能够快速开发的技术,支持持续的迭代,最高的工作效率,迅速,健壮性强.你想要精益求精并 ...
- Web Development Terms
I've come across lots of terms while learning web development. I'm feeling myself overwhelmed. Here ...
随机推荐
- AUC理解
https://www.zhihu.com/question/39840928 机器学习和统计里面的auc怎么理解?
- python中迭代器(转)
一.迭代器与for语句 网上许多文章说Python的for语句中,in关键字后面的对象是一个集合.例如 for i in [1,2,3] print i 上面代码中in关键字后面的对象[1,2,3]是 ...
- python json5
install pip install json5 test a.json: { 'a':'b', 'aa':['b1','b2']} =========================== impo ...
- js 获取input选择的图片的信息
1JS $("#btn").click(function () { var imageEle = document.getElementById("images" ...
- Unicode、UTF8与UTF16
1 概念 Unicode是国际组织制定的可以容纳世界上所有文字和符号的字符编码方案 UTF是“Unicode Transformation Format”的缩写,可以翻译成Unicode字符集转换格式 ...
- 第五章 二叉树(e4)层次遍历
- js switch case注意事项
今天写switch的时候发现没有达到预期效果,参照w3school的写法发现语法一致 想了一下,js是弱类型语言,是不是不支持number?试了一下将数字改为字符串,果然可以了 或者可以这样写:swi ...
- Python threading 单线程 timer重复调用函数
项目中需要使用定时器,每次都使用构造器函数调用: timer = threading.Timer(timerFlag, upload_position) timer.start() 打印线程后发现,每 ...
- OC 线程操作3 - NSOperation 实现线程间通信
#import "ViewController.h" @interface ViewController () /** 图片 */ @property (weak, nonatom ...
- 基于TCP的套接字
tcp服务端 1 ss = socket() #创建服务器套接字 2 ss.bind() #把地址绑定到套接字 3 ss.listen() #监听链接 4 inf_loop: #服务器无限循环 5 c ...