博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MSTest、NUnit、xUnit对照表
阅读量:5245 次
发布时间:2019-06-14

本文共 3040 字,大约阅读时间需要 10 分钟。

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

 

转载于:https://www.cnblogs.com/fmys/p/10206402.html

你可能感兴趣的文章
KDESVN中commit时出现containing working copy admin area is missing错误提示
查看>>
利用AOP写2PC框架(二)
查看>>
【动态规划】skiing
查看>>
java定时器的使用(Timer)
查看>>
ef codefirst VS里修改数据表结构后更新到数据库
查看>>
boost 同步定时器
查看>>
[ROS] Chinese MOOC || Chapter-4.4 Action
查看>>
简单的数据库操作
查看>>
解决php -v查看到版本与phpinfo()版本不一致问题
查看>>
iOS-解决iOS8及以上设置applicationIconBadgeNumber报错的问题
查看>>
亡灵序曲-The Dawn
查看>>
Redmine
查看>>
帧的最小长度 CSMA/CD
查看>>
xib文件加载后设置frame无效问题
查看>>
编程算法 - 左旋转字符串 代码(C)
查看>>
IOS解析XML
查看>>
Python3多线程爬取meizitu的图片
查看>>
树状数组及其他特别简单的扩展
查看>>
zookeeper适用场景:分布式锁实现
查看>>
110104_LC-Display(液晶显示屏)
查看>>