MSTest、NUnit、xUnit.net 属性和断言对照表
MSTest、NUnit、xUnit.net 属性对照表
MSTest | NUnit | xUnit.net | Comments |
[TestMethod] | [Test] | [Fact] |
Marks a test method. |
[TestClass] | [TestFixture] | n/a |
xUnit.net does not require an attribute for a test class; it looks for all test methods in all public (exported) classes in the assembly. |
[ExpectedException] | [ExpectedException] |
Assert.Throws Record.Exception |
xUnit.net has done away with the ExpectedException attribute in favor of Assert.Throws. |
[TestInitialize] | [SetUp] | Constructor |
We believe that use of [SetUp]is generally bad. However, you can implement a parameterless constructor as a direct replacement. |
[TestCleanup] | [TearDown] | IDisposable.Dispose |
We believe that use of[TearDown] is generally bad. However, you can implementIDisposable.Dispose as a direct replacement. |
[ClassInitialize] | [TestFixtureSetUp] | IUseFixture<T> |
To get per-fixture setup, implement IUseFixture<T> on your test class. |
[ClassCleanup] | [TestFixtureTearDown] | IUseFixture<T> |
To get per-fixture teardown, implement IUseFixture<T> on your test class. |
[Ignore] | [Ignore] | [Fact(Skip="reason")] |
Set the Skip parameter on the[Fact] attribute to temporarily skip a test. |
[Timeout] | [Timeout] | [Fact(Timeout=n)] |
Set the Timeout parameter on the [Fact] attribute to cause a test to fail if it takes too long to run. Note that the timeout value for xUnit.net is in milliseconds. |
[TestCategory] |
[Category] |
[Trait] | |
[TestProperty] | [Property] | [Trait] |
Set arbitrary metadata on a test |
[DataSource] | n/a | [Theory], [XxxData] |
Theory (data-driven test). |
MSTest、NUnit、xUnit.net 断言对照表
MSTest | NUnit | xUnit.net | Comments |
AreEqual | AreEqual | Equal |
MSTest and xUnit.net support generic versions of this method |
AreNotEqual | AreNotEqual | NotEqual |
MSTest and xUnit.net support generic versions of this method |
AreNotSame | AreNotSame |
NotSame |
|
AreSame | AreSame |
Same |
|
Contains (on CollectionAssert) |
Contains |
Contains |
|
n/a | DoAssert |
n/a |
|
DoesNotContain (on CollectionAssert) |
n/a |
DoesNotContain |
|
n/a | n/a | DoesNotThrow |
Ensures that the code does not throw any exceptions |
Fail | Fail | n/a |
xUnit.net alternative: Assert.True(false, "message") |
n/a | Pass | n/a | |
n/a | Greater | n/a |
xUnit.net alternative: Assert.True(x > y) |
n/a |
GreaterOrEqual |
n/a | |
Inconclusive | Ignore |
n/a |
|
n/a | n/a | InRange |
Ensures that a value is in a given inclusive range (note: NUnit and MSTest have limited support for InRange on their AreEqual methods) |
n/a | IsAssignableFrom |
IsAssignableFrom |
|
n/a | IsEmpty |
Empty |
|
IsFalse | IsFalse |
False |
|
IsInstanceOfType | IsInstanceOfType |
IsType |
|
n/a | IsNaN | n/a |
xUnit.net alternative: Assert.True(double.IsNaN(x)) |
n/a | IsNotAssignableFrom | n/a |
xUnit.net alternative: Assert.False(obj is Type); |
n/a | IsNotEmpty |
NotEmpty |
|
IsNotInstanceOfType | IsNotInstanceOfType |
IsNotType |
|
IsNotNull | IsNotNull |
NotNull |
|
IsNull | IsNull |
Null |
|
IsTrue | IsTrue |
True |
|
n/a | Less | n/a |
xUnit.net alternative: Assert.True(x < y) |
n/a |
LessOrEqual |
n/a | |
n/a | n/a |
NotInRange |
Ensures that a value is not in a given inclusive range |
n/a | Throws | Throws |
Ensures that the code throws an exact exception |
n/a |
IsAssignableFrom |
n/a | |
n/a | IsNotAssignableFrom |
n/a |
参考资料
- Using Traits with different test frameworks in the Unit Test Explorer
- Testing Framework Comparision with xUnit.net
MSTest、NUnit、xUnit.net 属性和断言对照表的更多相关文章
- MSTest/NUnit 单元测试 代码覆盖率试用 OpenCover 和ReportGenerator
VS自带是单元测试代码覆盖率(VS自带这个是最佳选择)需要企业版才有.很蛋疼...... 1.下载安装OpenCover 和ReportGenerator. 关于这2个是干啥的百度下.简单说就是可以分 ...
- Jenkins结合.net平台工具之Nunit
有时候我们需要对从git上拉取的项目进行单元测通过以后才可以发布到测试环境,.net平台下单元测试的框架也很多例如mstest,nunit,xunit等,下面以Nunit为例讲解如何通过Jenkins ...
- ASP.NET Core开发者成长路线图
目录 ASP.NET Core开发者路线图RoadMap 免责声明 请给一个星星! ⭐ 路线图 资源 总结 贡献 许可协议 ASP.NET Core开发者路线图RoadMap 来源: MoienTaj ...
- ASP.NET Core开发者指南
ASP.NET Core开发者指南 2019年ASP.NET Core开发者指南: 你可以在下面找到一张图,该图展示了你可以选取的路径及你想学习的库,从而成为一名 ASP.NET Core 开发者.“ ...
- 2019年ASP.NET Core学习路线
- [先决条件] + C# + Entity Framework + ASP.NET Core + SQL 基础知识 - [通用开发技能] + 学习 GIT, 在 GitHub 中创建开源项目 + 掌 ...
- ASP.NET Core开发者指南(转发)
ASP.NET Core开发者指南 2019年ASP.NET Core开发者指南: 你可以在下面找到一张图,该图展示了你可以选取的路径及你想学习的库,从而成为一名 ASP.NET Core 开发者.& ...
- Unit Testing with NSubstitute
These are the contents of my training session about unit testing, and also have some introductions a ...
- .NET Core Ecosystem
.NET .NET Blog Application Models Web Mobile Desktop Microservices Gaming Machine Learning Cloud Int ...
- Nunit与Xunit介绍
Nunit安装 首先说下,nunit2.X与3.X版本需要安装不同的vs扩展. nunit2.x安装 安装如上3个,辅助创建nunit测试项目与在vs中运行单元测试用例 . 1.Nunit2 Test ...
随机推荐
- xtrabackup备份与恢复实践
说明 xtrabackup --percona 特点: 开源,在线备份innodb表 支持限速备份,避免对业务造成影响 支持流备 支持增量备份 支持备份文件压缩与加密 支持并行备份与恢复,速度快 ...
- codevs 1163 访问艺术馆
1163 访问艺术馆 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备,打算到艺术馆盗画.艺术馆的结 ...
- for 循环
#include <iostream> int main(){ ; ; val <= ; ++val) { sum += val; } std::cout << &quo ...
- SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' 解决办法
当跑jndi项目时抛出:org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' fo ...
- return exit _exit
(1)进程终止: C程序的终止分为两种:正常终止和异常终止. 正常终止分为: return, exit, _exit, _Exit, pthreade_exit. 异常中指分为: abort, SIG ...
- LightOJ 1094 - Farthest Nodes in a Tree(树的直径)
http://acm.hust.edu.cn/vjudge/contest/121398#problem/H 不是特别理解,今天第一次碰到这种问题.给个链接看大神的解释吧 http://www.cnb ...
- 揭开HTTP网络协议神秘面纱系列(二)
HTTP报文内的HTTP信息 HTTP协议交互的信息被称为HTTP报文,请求端的HTTP报文叫做请求报文,响应端的叫做响应报文. HTTP为了提升传输速率,其在传输数据时,按照数据原样进行压缩传输,相 ...
- 【随笔】mOnOwall添加端口映射
mOnOwall是一个完整的嵌入防火墙软件包,当与一台嵌入个人电脑一起使用时,在免费使用自由软件的基础上,提供具备商业防火墙所有重要特性(包括易用). 这里通过配置mOnOwall的端口设置映射功能, ...
- jetty 最后版本类库树, 基本上大多数应用都够了
d:\jetty-distribution-8.1.17.v20150415\lib\annotations\javax.annotation-1.1.0.v201108011116.jarjavax ...
- Xshell连接虚拟机
一般连接虚拟机失败 原因1:ip地址错误 当输入 ifconfig 只有lo没有eth0,或者有eth0,但eth0中确没有inet addr这一行 输入命令:dhclient eth0 就可以了