一款简单易用的.Net 断言测试框架 : Shouldly
GitHub地址:https://github.com/shouldly/shouldly
Shouldly的官方文档:http://docs.shouldly-lib.net/
Nuget安装:
在测试类中引用:
using Shouldly;
用法 :
//验证
UsingDbContext(context =>
{
var bill = context.Bills.FirstOrDefault();
bill.ShouldNotBeNull();
});
我们看一下,ShouldNotBeNull是如何定义的, 其实就是在在原类型的基础上加的扩展方法。
namespace Shouldly
{
[DebuggerStepThrough]
[ShouldlyMethods]
public static class ShouldBeNullExtensions
{
public static void ShouldBeNull<T>(this T actual);
public static void ShouldBeNull<T>(this T actual, string customMessage);
public static void ShouldBeNull<T>(this T actual, [InstantHandle] Func<string> customMessage);
[ContractAnnotation("actual:null => halt")]
public static void ShouldNotBeNull<T>(this T actual);
[ContractAnnotation("actual:null => halt")]
public static void ShouldNotBeNull<T>(this T actual, string customMessage);
[ContractAnnotation("actual:null => halt")]
public static void ShouldNotBeNull<T>(this T actual, [InstantHandle] Func<string> customMessage);
}
}
[DebuggerStepThrough]
[ShouldlyMethods]
public static class ShouldBeTestExtensions
{
public static void ShouldBe(this decimal actual, decimal expected, decimal tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldBe(this DateTime actual, DateTime expected, TimeSpan tolerance);
public static void ShouldBe(this DateTime actual, DateTime expected, TimeSpan tolerance, string customMessage);
public static void ShouldBe(this DateTime actual, DateTime expected, TimeSpan tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldBe(this DateTimeOffset actual, DateTimeOffset expected, TimeSpan tolerance);
public static void ShouldBe(this DateTimeOffset actual, DateTimeOffset expected, TimeSpan tolerance, string customMessage);
public static void ShouldBe(this DateTimeOffset actual, DateTimeOffset expected, TimeSpan tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldBe(this TimeSpan actual, TimeSpan expected, TimeSpan tolerance);
public static void ShouldBe(this TimeSpan actual, TimeSpan expected, TimeSpan tolerance, string customMessage);
public static void ShouldBe(this TimeSpan actual, TimeSpan expected, TimeSpan tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldBe<T>(this T actual, T expected);
public static void ShouldBe<T>(this T actual, T expected, string customMessage);
public static void ShouldBe<T>(this T actual, T expected, [InstantHandle] Func<string> customMessage);
public static void ShouldBe<T>(this IEnumerable<T> actual, IEnumerable<T> expected, bool ignoreOrder = false);
public static void ShouldBe(this decimal actual, decimal expected, decimal tolerance, string customMessage);
public static void ShouldBe<T>(this IEnumerable<T> actual, IEnumerable<T> expected, bool ignoreOrder, [InstantHandle] Func<string> customMessage);
public static void ShouldBe<T>(this IEnumerable<T> actual, IEnumerable<T> expected, bool ignoreOrder, string customMessage);
public static void ShouldBe(this IEnumerable<decimal> actual, IEnumerable<decimal> expected, decimal tolerance, string customMessage);
public static void ShouldBe(this decimal actual, decimal expected, decimal tolerance);
public static void ShouldBe(this double actual, double expected, double tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldBe(this double actual, double expected, double tolerance, string customMessage);
public static void ShouldBe(this double actual, double expected, double tolerance);
public static void ShouldBe(this IEnumerable<decimal> actual, IEnumerable<decimal> expected, decimal tolerance);
public static void ShouldBe(this IEnumerable<float> actual, IEnumerable<float> expected, double tolerance, string customMessage);
public static void ShouldBe(this IEnumerable<float> actual, IEnumerable<float> expected, double tolerance);
public static void ShouldBe(this IEnumerable<float> actual, IEnumerable<float> expected, double tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldBe(this IEnumerable<double> actual, IEnumerable<double> expected, double tolerance, string customMessage);
public static void ShouldBe(this IEnumerable<double> actual, IEnumerable<double> expected, double tolerance);
public static void ShouldBe(this float actual, float expected, double tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldBe(this float actual, float expected, double tolerance, string customMessage);
public static void ShouldBe(this float actual, float expected, double tolerance);
public static void ShouldBe(this IEnumerable<decimal> actual, IEnumerable<decimal> expected, decimal tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldBe(this IEnumerable<double> actual, IEnumerable<double> expected, double tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldBeAssignableTo(this object actual, Type expected, [InstantHandle] Func<string> customMessage);
public static void ShouldBeAssignableTo(this object actual, Type expected, string customMessage);
public static void ShouldBeAssignableTo(this object actual, Type expected);
public static T ShouldBeAssignableTo<T>(this object actual, [InstantHandle] Func<string> customMessage);
public static T ShouldBeAssignableTo<T>(this object actual);
public static T ShouldBeAssignableTo<T>(this object actual, string customMessage);
public static void ShouldBeGreaterThan<T>(this T actual, T expected) where T : IComparable<T>;
public static void ShouldBeGreaterThan<T>(this T actual, T expected, IComparer<T> comparer);
public static void ShouldBeGreaterThan<T>(this T actual, T expected, IComparer<T> comparer, string customMessage);
public static void ShouldBeGreaterThan<T>(this T actual, T expected, IComparer<T> comparer, Func<string> customMessage);
public static void ShouldBeGreaterThan<T>(this T actual, T expected, string customMessage) where T : IComparable<T>;
public static void ShouldBeGreaterThan<T>(this T actual, T expected, [InstantHandle] Func<string> customMessage) where T : IComparable<T>;
public static void ShouldBeGreaterThanOrEqualTo<T>(this T actual, T expected, [InstantHandle] Func<string> customMessage) where T : IComparable<T>;
public static void ShouldBeGreaterThanOrEqualTo<T>(this T actual, T expected, IComparer<T> comparer, string customMessage);
public static void ShouldBeGreaterThanOrEqualTo<T>(this T actual, T expected, IComparer<T> comparer);
public static void ShouldBeGreaterThanOrEqualTo<T>(this T actual, T expected, string customMessage) where T : IComparable<T>;
public static void ShouldBeGreaterThanOrEqualTo<T>(this T actual, T expected) where T : IComparable<T>;
public static void ShouldBeGreaterThanOrEqualTo<T>(this T actual, T expected, IComparer<T> comparer, Func<string> customMessage);
public static void ShouldBeInRange<T>(this T actual, T from, T to, [InstantHandle] Func<string> customMessage) where T : IComparable<T>;
public static void ShouldBeInRange<T>(this T actual, T from, T to, string customMessage) where T : IComparable<T>;
public static void ShouldBeInRange<T>(this T actual, T from, T to) where T : IComparable<T>;
public static void ShouldBeLessThan<T>(this T actual, T expected, IComparer<T> comparer, Func<string> customMessage);
public static void ShouldBeLessThan<T>(this T actual, T expected, IComparer<T> comparer, string customMessage);
public static void ShouldBeLessThan<T>(this T actual, T expected, IComparer<T> comparer);
public static void ShouldBeLessThan<T>(this T actual, T expected, string customMessage) where T : IComparable<T>;
public static void ShouldBeLessThan<T>(this T actual, T expected) where T : IComparable<T>;
public static void ShouldBeLessThan<T>(this T actual, T expected, [InstantHandle] Func<string> customMessage) where T : IComparable<T>;
public static void ShouldBeLessThanOrEqualTo<T>(this T actual, T expected, [InstantHandle] Func<string> customMessage) where T : IComparable<T>;
public static void ShouldBeLessThanOrEqualTo<T>(this T actual, T expected, IComparer<T> comparer, Func<string> customMessage);
public static void ShouldBeLessThanOrEqualTo<T>(this T actual, T expected, IComparer<T> comparer);
public static void ShouldBeLessThanOrEqualTo<T>(this T actual, T expected, string customMessage) where T : IComparable<T>;
public static void ShouldBeLessThanOrEqualTo<T>(this T actual, T expected) where T : IComparable<T>;
public static void ShouldBeLessThanOrEqualTo<T>(this T actual, T expected, IComparer<T> comparer, string customMessage);
public static void ShouldBeNegative(this decimal actual);
public static void ShouldBeNegative(this decimal actual, string customMessage);
public static void ShouldBeNegative(this decimal actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBeNegative(this double actual, string customMessage);
public static void ShouldBeNegative(this double actual);
public static void ShouldBeNegative(this double actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBeNegative(this float actual);
public static void ShouldBeNegative(this long actual, string customMessage);
public static void ShouldBeNegative(this short actual, string customMessage);
public static void ShouldBeNegative(this short actual);
public static void ShouldBeNegative(this long actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBeNegative(this long actual);
public static void ShouldBeNegative(this int actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBeNegative(this int actual, string customMessage);
public static void ShouldBeNegative(this int actual);
public static void ShouldBeNegative(this short actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBeNegative(this float actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBeNegative(this float actual, string customMessage);
public static T ShouldBeOfType<T>(this object actual);
public static T ShouldBeOfType<T>(this object actual, string customMessage);
public static void ShouldBeOfType(this object actual, Type expected, string customMessage);
public static void ShouldBeOfType(this object actual, Type expected, [InstantHandle] Func<string> customMessage);
public static T ShouldBeOfType<T>(this object actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBeOfType(this object actual, Type expected);
public static void ShouldBeOneOf<T>(this T actual, T[] expected, string customMessage);
public static void ShouldBeOneOf<T>(this T actual, params T[] expected);
public static void ShouldBeOneOf<T>(this T actual, T[] expected, [InstantHandle] Func<string> customMessage);
public static void ShouldBePositive(this float actual, string customMessage);
public static void ShouldBePositive(this decimal actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBePositive(this short actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBePositive(this short actual, string customMessage);
public static void ShouldBePositive(this short actual);
public static void ShouldBePositive(this decimal actual);
public static void ShouldBePositive(this decimal actual, string customMessage);
public static void ShouldBePositive(this float actual);
public static void ShouldBePositive(this double actual);
public static void ShouldBePositive(this double actual, string customMessage);
public static void ShouldBePositive(this double actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBePositive(this float actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBePositive(this long actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBePositive(this long actual, string customMessage);
public static void ShouldBePositive(this long actual);
public static void ShouldBePositive(this int actual, [InstantHandle] Func<string> customMessage);
public static void ShouldBePositive(this int actual, string customMessage);
public static void ShouldBePositive(this int actual);
public static void ShouldBeSameAs(this object actual, object expected, string customMessage);
public static void ShouldBeSameAs(this object actual, object expected, [InstantHandle] Func<string> customMessage);
public static void ShouldBeSameAs(this object actual, object expected);
[ContractAnnotation("actual:null,expected:null => halt")]
public static void ShouldNotBe<T>(this T actual, T expected, [InstantHandle] Func<string> customMessage);
[ContractAnnotation("actual:null,expected:null => halt")]
public static void ShouldNotBe<T>(this T actual, T expected, string customMessage);
[ContractAnnotation("actual:null,expected:null => halt")]
public static void ShouldNotBe<T>(this T actual, T expected);
public static void ShouldNotBe(this DateTimeOffset actual, DateTimeOffset expected, TimeSpan tolerance, string customMessage);
public static void ShouldNotBe(this TimeSpan actual, TimeSpan expected, TimeSpan tolerance, string customMessage);
public static void ShouldNotBe(this TimeSpan actual, TimeSpan expected, TimeSpan tolerance);
public static void ShouldNotBe(this DateTimeOffset actual, DateTimeOffset expected, TimeSpan tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldNotBe(this DateTimeOffset actual, DateTimeOffset expected, TimeSpan tolerance);
public static void ShouldNotBe(this DateTime actual, DateTime expected, TimeSpan tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldNotBe(this DateTime actual, DateTime expected, TimeSpan tolerance, string customMessage);
public static void ShouldNotBe(this DateTime actual, DateTime expected, TimeSpan tolerance);
public static void ShouldNotBe(this TimeSpan actual, TimeSpan expected, TimeSpan tolerance, [InstantHandle] Func<string> customMessage);
public static void ShouldNotBeAssignableTo(this object actual, Type expected);
public static void ShouldNotBeAssignableTo<T>(this object actual, [InstantHandle] Func<string> customMessage);
public static void ShouldNotBeAssignableTo<T>(this object actual, string customMessage);
public static void ShouldNotBeAssignableTo(this object actual, Type expected, [InstantHandle] Func<string> customMessage);
public static void ShouldNotBeAssignableTo(this object actual, Type expected, string customMessage);
public static void ShouldNotBeAssignableTo<T>(this object actual);
public static void ShouldNotBeInRange<T>(this T actual, T from, T to) where T : IComparable<T>;
public static void ShouldNotBeInRange<T>(this T actual, T from, T to, [InstantHandle] Func<string> customMessage) where T : IComparable<T>;
public static void ShouldNotBeInRange<T>(this T actual, T from, T to, string customMessage) where T : IComparable<T>;
public static void ShouldNotBeOfType(this object actual, Type expected, string customMessage);
public static void ShouldNotBeOfType<T>(this object actual, string customMessage);
public static void ShouldNotBeOfType(this object actual, Type expected);
public static void ShouldNotBeOfType(this object actual, Type expected, [InstantHandle] Func<string> customMessage);
public static void ShouldNotBeOfType<T>(this object actual);
public static void ShouldNotBeOfType<T>(this object actual, [InstantHandle] Func<string> customMessage);
public static void ShouldNotBeOneOf<T>(this T actual, T[] expected, [InstantHandle] Func<string> customMessage);
public static void ShouldNotBeOneOf<T>(this T actual, T[] expected, string customMessage);
public static void ShouldNotBeOneOf<T>(this T actual, params T[] expected);
public static void ShouldNotBeSameAs(this object actual, object expected, [InstantHandle] Func<string> customMessage);
public static void ShouldNotBeSameAs(this object actual, object expected, string customMessage);
public static void ShouldNotBeSameAs(this object actual, object expected);
}
当测试失败时,
异常测试:
var bill = context.Bills.FirstOrDefault();
Should.Throw<DivideByZeroException>(() =>
{
bill.SetBmiNoPay();
});
测试结果:
一款简单易用的.Net 断言测试框架 : Shouldly的更多相关文章
- 推荐一款简单易用线上引流测试工具:GoReplay
一. 引流测试产生背景 日常大部分的测试工作都是在测试环境下,通过模拟用户的行为来对系统进行验证,包括功能以及性能.在这个过程中,你可能会遇到以下问题: 用户访问行为比较复杂,模拟很难和用户行为一致, ...
- 简单易用的leetcode开发测试工具(npm)
描述 最近在用es6解leetcode,当问题比较复杂时,有可能修正了新的错误,却影响了前面的流程.要用通用的测试工具,却又有杀鸡用牛刀的感觉,所以就写了个简单易用的leetcode开发测试工具,分享 ...
- 设计与开发一款简单易用的Web报表工具(支持常用关系数据及hadoop、hbase等)
EasyReport是一个简单易用的Web报表工具(支持Hadoop,HBase及各种关系型数据库),它的主要功能是把SQL语句查询出的行列结构转换成HTML表格(Table),并支持表格的跨行(Ro ...
- Criterion - 一个简单可扩展的 C 语言测试框架
A dead-simple, yet extensible, C test framework. Philosophy Most test frameworks for C require a lot ...
- 如何以最简单的方式安装 KALI 渗透测试框架系统
0x01 第一步下载 KALI 百度搜索 KALI 官网,找到下载区,我选的是 64 位标准版,但是推荐下载 32 位(功能貌似更全) 这个为下载后的 iso 镜像文件 0x02 第二步打开虚拟机,配 ...
- 简单易用的堡垒机系统—Teleport
简单易用的堡垒机系统-Teleport 官方文档:http://teleport.eomsoft.net/doc#!1 一.Teleport介绍 Teleport是触维软件推出的一款简单易用的堡垒机 ...
- 消灭Bug!十款免费移动应用测试框架推荐
对于移动应用开发者而言,Bug往往是最让人头疼的一大问题.不同于时时刻刻可以修补的Web App,移动App中的Bug往往隐藏得很深,甚至有时候等到用户使用才显现出来,这么一来开发者搞不好就会赔了 ...
- hapi lab测试框架简单使用
1. 依赖安装 yarn init yarn add lab code 2. 基本模式 const Lab = require('lab'); const Code = require('code') ...
- [.net 面向对象程序设计进阶] (22) 团队开发利器(一)简单易用的代码管理工具VSS
[.net 面向对象程序设计进阶] (22) 团队开发利器(一)简单易用的代码管理工具VSS 本篇要点:在进阶篇快要结束的时候说说源代码管理器,我们的开发,不是一个人可以完成的事,团队协作很重要,而且 ...
随机推荐
- 哈密顿绕行世界问题---hdu2181(全排列问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2181 题意很容易理解,dfs就可以了 #include <iostream> #inclu ...
- 怎样在QML应用中创建一个Context Menu
我们在非常多的系统中看见能够在屏幕的一个地方长按,然后就能够依据当前显示的上下文弹出一个菜单. 菜单中能够有一些选项,比方删除,改动该项.这样的一般在ListView或GridView中常见.今天,我 ...
- Win2003X64位,IIS6.0 32位 浏览报错的解决方案
目录 问题案例 原因分析 解决问题 其他 问题案例 1)服务浏览出现: service unavailable 2)服务浏览出现:HTTP 404 当前页找不到 3)在事件查看器:应用程序中报错:在同 ...
- Jersey 出现415 MediaType is not supported问题的原因
前段时间在使用jersey的时候,经常碰到这个问题,一直没有找到真正的原因.找了其他的解决访问,比如使用jackson以及手动转为json再返回给前端. 后续发现问题出在domain对象属性类型和se ...
- Java编程:将具有父子关系的数据库表数据转换为树形结构,支持无限层级
在平时的开发工作中,经常遇到这样一个场景,在数据库中存储了具有父子关系的数据,需要将这些数据以树形结构的形式在界面上进行展示.本文的目的是提供了一个通用的编程模型,解决将具有父子关系的数据转换成树形结 ...
- 登录plsql 报错 the account is locked --用户被锁
登录数据库服务器,进入oracle用户下: [root@uumsnormal-oracle admin]# su - oracle [oracle@uumsnormal-oracle ~]$ sqlp ...
- how to use greendao in android studio
http://www.arjunsk.com/android/use-greendao-android-studio/ 1.新建一个java文件MainGenerator.java: import d ...
- 通过进程名称删除进程 ps -ef
删除进程名为udpserver的进程. kill -9 $(ps -ef|grep udpserver | grep java|awk '{print $2}' ). 1.通过进程名取得进程号: ps ...
- Oracle获取当前session ID的方法
1.使用v$mystat视图获取当前session的ID select sid from v$mystat; 2.使用userenv内部函数获取当前session的ID select userenv( ...
- rf调参小结
转自http://www.cnblogs.com/pinard/p/6160412.html 1. scikit-learn随机森林类库概述 在scikit-learn中,RF的分类类是RandomF ...