当前位置: 首页 > 工具软件 > xUnit.net > 使用案例 >

MSTest、NUnit、xUnit.net 属性对照表

柳奇希
2023-12-01

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

 
 
 类似资料: