一款简单易用的.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 本篇要点:在进阶篇快要结束的时候说说源代码管理器,我们的开发,不是一个人可以完成的事,团队协作很重要,而且 ...
随机推荐
- MySQL优化(一):MySQL分库分表
一.分库分表种类 1.垂直拆分 在考虑数据拆分的时候,一般情况下,应该先考虑垂直拆分.垂直可以理解为分出来的库表结构是互相独立各不相同的. - 如果有多个业务,每个业务直接关联性不大,那么就可以把每个 ...
- 002-Spring Boot将WAR文件部署到Tomcat
一.概述 springboot 带有内置Tomcat 服务器,可以直接将项目打包成jar运行,如果在需要把项目打成war包,使用外置tomcat部署.下面是将springboot项目部署为war项目的 ...
- java-mybaits-00601-查询缓存-一级缓存、二级缓存
1.什么是查询缓存 mybatis提供查询缓存,用于减轻数据压力,提高数据库性能. mybaits提供一级缓存,和二级缓存. 一级缓存是SqlSession级别的缓存. 在操作数据库时需要构造 sql ...
- 七、Mosquito 集群搭建
本章主要讲述Mosquitto 集群搭建的两种方式 1.进行双服务器搭建 2.进行多服务器搭建 一.Mosquitto的分布式集群部署 如果需要做并发量很大的时候就需要考虑做集群处理,但是我在查找资料 ...
- MySQLdb使用批量插入executemany方法插入mysql
python的MySQLdb库可以使用批量操作executemany,进行多行插入. 比如向user表(username,salt,pwd)插入数据,具体的sql语句如下: sql = 'INSERT ...
- Python第一个爬虫学习
在网上查看大神的关于Python爬虫的文章,代码如下: #coding=utf-8 import urllib import re def getHtml(url): page = urllib.ur ...
- 6 TensorFlow实现cnn识别手写数字
------------------------------------ 写在开头:此文参照莫烦python教程(墙裂推荐!!!) ---------------------------------- ...
- The Air Jordan 4 Oreo Remastered would be re-released in 2015
May be the Jordan 4 Oreo probably the most anticipated pair among the remastered Jordans for 2015? W ...
- js null, undefined, NaN, ‘’, false, 0, ==, === 全验证
<html> <head> <meta charset="utf-8" /> </head> <body> <in ...
- php等守护进程监控脚本(转载 http://www.9958.pw/post/php_script_scan)
此脚本用户守护监控进程的执行情况,因为有的时候,我们用各类开发语言做的守护进程可能会因为一些特殊情况被退出,所以此脚本就是为了重启这些进程 代码: #!/bin/bash EMAIL='9958_pw ...