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

 

参考资料

  1. Using Traits with different test frameworks in the Unit Test Explorer
  2. Testing Framework Comparision with xUnit.net

MSTest、NUnit、xUnit.net 属性和断言对照表的更多相关文章

  1. MSTest/NUnit 单元测试 代码覆盖率试用 OpenCover 和ReportGenerator

    VS自带是单元测试代码覆盖率(VS自带这个是最佳选择)需要企业版才有.很蛋疼...... 1.下载安装OpenCover 和ReportGenerator. 关于这2个是干啥的百度下.简单说就是可以分 ...

  2. Jenkins结合.net平台工具之Nunit

    有时候我们需要对从git上拉取的项目进行单元测通过以后才可以发布到测试环境,.net平台下单元测试的框架也很多例如mstest,nunit,xunit等,下面以Nunit为例讲解如何通过Jenkins ...

  3. ASP.NET Core开发者成长路线图

    目录 ASP.NET Core开发者路线图RoadMap 免责声明 请给一个星星! ⭐ 路线图 资源 总结 贡献 许可协议 ASP.NET Core开发者路线图RoadMap 来源: MoienTaj ...

  4. ASP.NET Core开发者指南

    ASP.NET Core开发者指南 2019年ASP.NET Core开发者指南: 你可以在下面找到一张图,该图展示了你可以选取的路径及你想学习的库,从而成为一名 ASP.NET Core 开发者.“ ...

  5. 2019年ASP.NET Core学习路线

    - [先决条件] + C# + Entity Framework + ASP.NET Core + SQL 基础知识 - [通用开发技能] + 学习 GIT, 在 GitHub 中创建开源项目 + 掌 ...

  6. ASP.NET Core开发者指南(转发)

    ASP.NET Core开发者指南 2019年ASP.NET Core开发者指南: 你可以在下面找到一张图,该图展示了你可以选取的路径及你想学习的库,从而成为一名 ASP.NET Core 开发者.& ...

  7. Unit Testing with NSubstitute

    These are the contents of my training session about unit testing, and also have some introductions a ...

  8. .NET Core Ecosystem

    .NET .NET Blog Application Models Web Mobile Desktop Microservices Gaming Machine Learning Cloud Int ...

  9. Nunit与Xunit介绍

    Nunit安装 首先说下,nunit2.X与3.X版本需要安装不同的vs扩展. nunit2.x安装 安装如上3个,辅助创建nunit测试项目与在vs中运行单元测试用例 . 1.Nunit2 Test ...

随机推荐

  1. XidianOJ 1097 焊板子的xry111

    题目描述 我们知道xry111不仅仅代码写的棒,硬件也不是一般人可以比拟的,比如他可以左手右手加上嘴里叼着一个烙铁一起工作,同时焊接三块板子!Orz,现在他的实验室知道他这么厉害了,准备让他焊接N块板 ...

  2. 【226】C# 相关功能实现代码

    目录: 1. 实现代码的等待操作 2. 实现文件夹/文件打开操作 3. 建立事件模板,然后调用 4. 用代码在Form中写控件,同时可以编写控件数组 5. 用代码执行事件   1. 实现代码的等待操作 ...

  3. Allegro学习(http://www.asmyword.com/forum.php?mod=forumdisplay&fid=86)

    一.资源 1.网站推荐www.eda365.com,里面有很多有用的东西:当然还有官方代理商的网站http://www.pspice.com.cn/: 2.视频教程:有库源电气的视频教程,还有在www ...

  4. 2.Mybatis入门程序(单表的增删改成)

    这里讲的单表的增删改查,是由mapper代理的增删改查,先来看看步骤: 1.jar包的导入 2.配置全局的配置文件 3.建立接口 4.编写mapper.xml 5.测试 工程结构:这个你们自己可以调整 ...

  5. WebForm 简单控件、复合控件

    简单控件: Label:被编译成span 样式表里设置lable的高度:  display:inline-block; Text  --文本 ForeColor  --字体颜色 Visible  -- ...

  6. cocos2d-x 坐标系

    OPenGL坐标系:原点为屏幕左下角 屏幕坐标系:原点在屏幕左上角

  7. 联想扬天 电脑 键盘改默认fn功能键

    联想扬天电脑改键工具 windows 8 windows8.1 64位版本:http://support1.lenovo.com.cn/lenovo/wsi/Modules/DriverDetail. ...

  8. Hibernate 根据实体名称得到DB表名以及表对应的Sequence name

    DB: oracle 10g; entityName:com.signaldemand.flank.hibernate.model.实体名 1. 根据实体名获取DB表相对应的表名 Class<? ...

  9. iOS大神牛人的博客集合

    王巍的博客:王巍目前在日本横滨任职于LINE.工作内容主要进行Unity3D开发,8小时之外经常进行iOS/Mac开发.他的陈列柜中已有多款应用,其中番茄工作法工具非常棒. http://onevca ...

  10. CXF 入门:创建一个基于WS-Security标准的安全验证(CXF回调函数使用,)

    http://jyao.iteye.com/blog/1346547 注意:以下客户端调用代码中获取服务端ws实例,都是通过CXF 入门: 远程接口调用方式实现 直入正题! 以下是服务端配置 ==== ...