您的位置:首页 > 其它

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

2014-03-08 21:12 393 查看
MSTest、NUnit、xUnit.net 属性对照表

MSTestNUnitxUnit.netComments
[TestMethod][Test][Fact]Marks a test method.

[TestClass][TestFixture]n/axUnit.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]ConstructorWe believe that use of [SetUp]is generally bad. However, you can implement a parameterless constructor as a direct replacement.

[TestCleanup][TearDown]IDisposable.DisposeWe 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
AreEqualAreEqualEqualMSTest and xUnit.net support generic versions of this method

AreNotEqualAreNotEqualNotEqualMSTest and xUnit.net support generic versions of this method

AreNotSameAreNotSameNotSame

AreSameAreSameSame

Contains

(on CollectionAssert)

ContainsContains

n/aDoAssertn/a

DoesNotContain

(on CollectionAssert)

n/aDoesNotContain

n/an/aDoesNotThrowEnsures that the code does not throw any exceptions

FailFailn/axUnit.net alternative:

Assert.True(false, "message")

n/aPassn/a
n/aGreatern/axUnit.net alternative:

Assert.True(x > y)

n/aGreaterOrEqual

n/a
InconclusiveIgnoren/a

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

n/aIsAssignableFromIsAssignableFrom

n/aIsEmptyEmpty

IsFalseIsFalseFalse

IsInstanceOfTypeIsInstanceOfTypeIsType

n/aIsNaNn/axUnit.net alternative:

Assert.True(double.IsNaN(x))

n/aIsNotAssignableFromn/axUnit.net alternative:

Assert.False(obj is Type);

n/aIsNotEmptyNotEmpty

IsNotInstanceOfTypeIsNotInstanceOfTypeIsNotType

IsNotNullIsNotNullNotNull

IsNullIsNullNull

IsTrueIsTrueTrue

n/aLessn/axUnit.net alternative:

Assert.True(x < y)

n/aLessOrEqual

n/a
n/an/aNotInRange

Ensures that a value is not in a given inclusive range

n/aThrowsThrowsEnsures that the code throws an exact exception

n/aIsAssignableFrom

n/a
n/aIsNotAssignableFromn/a

参考资料

Using Traits with different test frameworks in the Unit Test Explorer

Testing Framework Comparision with xUnit.net
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: