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的更多相关文章

  1. 推荐一款简单易用线上引流测试工具:GoReplay

    一. 引流测试产生背景 日常大部分的测试工作都是在测试环境下,通过模拟用户的行为来对系统进行验证,包括功能以及性能.在这个过程中,你可能会遇到以下问题: 用户访问行为比较复杂,模拟很难和用户行为一致, ...

  2. 简单易用的leetcode开发测试工具(npm)

    描述 最近在用es6解leetcode,当问题比较复杂时,有可能修正了新的错误,却影响了前面的流程.要用通用的测试工具,却又有杀鸡用牛刀的感觉,所以就写了个简单易用的leetcode开发测试工具,分享 ...

  3. 设计与开发一款简单易用的Web报表工具(支持常用关系数据及hadoop、hbase等)

    EasyReport是一个简单易用的Web报表工具(支持Hadoop,HBase及各种关系型数据库),它的主要功能是把SQL语句查询出的行列结构转换成HTML表格(Table),并支持表格的跨行(Ro ...

  4. Criterion - 一个简单可扩展的 C 语言测试框架

    A dead-simple, yet extensible, C test framework. Philosophy Most test frameworks for C require a lot ...

  5. 如何以最简单的方式安装 KALI 渗透测试框架系统

    0x01 第一步下载 KALI 百度搜索 KALI 官网,找到下载区,我选的是 64 位标准版,但是推荐下载 32 位(功能貌似更全) 这个为下载后的 iso 镜像文件 0x02 第二步打开虚拟机,配 ...

  6. 简单易用的堡垒机系统—Teleport

    简单易用的堡垒机系统-Teleport 官方文档:http://teleport.eomsoft.net/doc#!1  一.Teleport介绍 Teleport是触维软件推出的一款简单易用的堡垒机 ...

  7. 消灭Bug!十款免费移动应用测试框架推荐

      对于移动应用开发者而言,Bug往往是最让人头疼的一大问题.不同于时时刻刻可以修补的Web App,移动App中的Bug往往隐藏得很深,甚至有时候等到用户使用才显现出来,这么一来开发者搞不好就会赔了 ...

  8. hapi lab测试框架简单使用

    1. 依赖安装 yarn init yarn add lab code 2. 基本模式 const Lab = require('lab'); const Code = require('code') ...

  9. [.net 面向对象程序设计进阶] (22) 团队开发利器(一)简单易用的代码管理工具VSS

    [.net 面向对象程序设计进阶] (22) 团队开发利器(一)简单易用的代码管理工具VSS 本篇要点:在进阶篇快要结束的时候说说源代码管理器,我们的开发,不是一个人可以完成的事,团队协作很重要,而且 ...

随机推荐

  1. 网络编程 - 1.简单的套接字通信/2.加上通信循环/3.bug修复/4.加上链接循环/5.模拟ssh远程执行命令

    1.简单的套接字通信 服务端 ''' 服务端 接电话 客户端 打电话 1.先启动服务端 2.服务端有两种套接字 1.phone 用来干接收链接的 2.conn 用来干收发消息的 ''' import ...

  2. apt-get 报 The following signatures were invalid: KEYEXPIRED 错误

    apt-get 原理: 参考:https://blog.csdn.net/a13526758473/article/details/79247478 apt对它所管理的每一个程序包都有一对公钥和私钥, ...

  3. (2.6)Mysql之SQL基础——存储引擎的查看与修改

    (2.6)Mysql之SQL基础——存储引擎的查看与修改 可以使用 show engines; 查看数据库支持的所有的存储引擎: 目录: 1.数据库级别存储引擎 1.1查看现在默认的存储引擎 1.2 ...

  4. 前端 javascript 数据类型

    JavaScript 中的数据类型分为原始类型和对象类型: 原始类型 数字 字符串 布尔值 对象类型 数组 “字典” ...

  5. vs开发nodejs api文档生成神器-apidoc

    直接生成文档的神器 apidoc 1 win+R 输入 cmd 回车 然后进入 nodejs 项目目录 例如 D:\NodeTest\newApp1 2  用npm安装 apidoc 直接输入 npm ...

  6. Sql order by 和 group BY 如何共同运用?

    如果声明了 GROUP BY 子句,输出就分成匹配一个或多个数值的不同组里. 如果出现了 HAVING 子句,那么它消除那些不满足给出条件的组. 如果声明了 ORDER BY 子句,那么返回的行是按照 ...

  7. Font Awesome-用CSS实现各种小图标icon

    Font Awesome为您提供可缩放的矢量图标,您可以使用CSS所提供的所有特性对它们进行更改,包括:大小.颜色.阴影或者其它任何支持的效果.官网:http://fontawesome.dashga ...

  8. UVA10763:Foreign Exchange&&UVA10340: All in All(水题)

    10763:水题不解释直接贴代码. #include <iostream> #include <string.h> #include <stdio.h> #incl ...

  9. jQery实现插入删除信息

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  10. 软工网络15团队作业1——团队组队&展示

    一.团队展示 1.队名:想不出队名 2.队员学号(标记组长) 201521123064 郭炜埕 201521123066 郑晓丽 201521123067 廖怡洁 201521123068 包梦榕 2 ...