MSTest、NUnit、xUnit.net 属性和断言对照表【转】

MSTest、NUnit、xUnit.net 属性对照表
MSTestNUnitxUnit.netComments
[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 断言对照表
MSTestNUnitxUnit.netComments
AreEqualAreEqualEqual

MSTest and xUnit.net support generic versions of this method

AreNotEqualAreNotEqualNotEqual

MSTest and xUnit.net support generic versions of this method

AreNotSameAreNotSame

NotSame

 
AreSameAreSame

Same

 

Contains 

(on CollectionAssert)

Contains

Contains

 
n/aDoAssert

n/a

 

DoesNotContain 

(on CollectionAssert)

n/a

DoesNotContain

 
n/an/aDoesNotThrow

Ensures that the code does not throw any exceptions

FailFailn/a

xUnit.net alternative:

Assert.True(false, "message")

n/aPassn/a 
n/aGreatern/a

xUnit.net alternative: 

Assert.True(x > y)

n/a

GreaterOrEqual

n/a 
InconclusiveIgnore

n/a

 
n/an/aInRange

Ensures that a value is in a given inclusive range (note: NUnit and MSTest have limited support for InRange on their AreEqual methods)

n/aIsAssignableFrom

IsAssignableFrom

 
n/aIsEmpty

Empty

 
IsFalseIsFalse

False

 
IsInstanceOfTypeIsInstanceOfType

IsType

 
n/aIsNaNn/a

xUnit.net alternative:

Assert.True(double.IsNaN(x))

n/aIsNotAssignableFromn/a

xUnit.net alternative: 

Assert.False(obj is Type);

n/aIsNotEmpty

NotEmpty

 
IsNotInstanceOfTypeIsNotInstanceOfType

IsNotType

 
IsNotNullIsNotNull

NotNull

 
IsNullIsNull

Null

 
IsTrueIsTrue

True

 
n/aLessn/a

xUnit.net alternative: 

Assert.True(x < y)

n/a

LessOrEqual

n/a 
n/an/a

NotInRange

Ensures that a value is not in a given inclusive range

n/aThrowsThrows

Ensures that the code throws an exact exception

n/a

IsAssignableFrom

n/a 
n/aIsNotAssignableFrom

n/a

 

参考资料

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

转载于:https://www.cnblogs.com/shuaijie/articles/5643717.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值