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 ...
随机推荐
- AX2009按照批次生产日期预留
AX2009如果想按照批处理号预留,它默认是按照InventBatchId排序的,但并不是InventBatchd小的批次的生产日期就早,所以这个逻辑得改一下,让它按照InventBatch的Prod ...
- APP都有哪些类型?
Web App的优势:(线上应用) 1.开发成本低 2.适配多种移动设备成本低 3.跨平台和终端 4.迭代更新容易 5.无需安装成本 Web App的劣势: 1.浏览的体验短期内还无法超越原生应用 2 ...
- ZOJ3778--一道水题
Description As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the ...
- 循序渐进Python3(七) --1-- 面向对象
Python 面向对象 什么是面向对象编程? 面向对象编程是一种程序设计范式 对现实世界建立对象模型 把程序看作不同对象的相互调用 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Py ...
- js 正则 以字母开头必须有 大小写字母数字组成 可以有“@"或 ”.“
js 正则 以字母开头必须有 大小写字母数字组成 可以有“@"或 ”.“ var reg = /^[a-zA-Z]{1}(?=.*[a-z])(?=.*[A-Z])[a-zA-Z\d_@ ...
- delphi对象赋值
Delphi的对象之间赋值主要要注意几个方面的问题: 1.对象之间的 :=赋值只是地址赋值,即是将当前对象的地址赋值到变量中,定义的变量可以是不用初始化的,在内存中两个变量指向的是同一地址空间: ...
- iOS开发-Alcatraz插件管理
CocoaPod负责iOS开发中的引用类库的管理,Alcatraz中文翻译阿尔卡特拉斯岛,也有人称之为恶魔岛,主要是负责管理第三方Xcode 插件.模版以及颜色配置的工具,直接集成到 Xcode 的图 ...
- WebStorm常用设置和常用快捷键
今天下载了最新版本的WebStorm 7.反正又要重新设置一番了,干脆写下来记录到博客里面,免得以后每次忘了还要到处搜索比较麻烦. 加速 禁用多余的插件,关掉没必要的代码检查项.webstorm慢的原 ...
- calc()问题
什么是calc()? 学习calc()之前,我们有必要先知道calc()是什么?只有知道了他是个什么东东?在实际运用中更好的使用他. calc() 从字面我们可以把他理解为一个函数function.其 ...
- [MyBean-插件]MyBean通用报表免费无限制版本发布
[优点] 1.开发时无需安装报表组件(可以直接用编译好的文件,注意版权说明,请自行编译一次相应的报表插件文件). 2.无带包烦恼所有版本Delphi都可以使用,不拖累Delphi版本的 ...