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


    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

    出处:https://www.cnblogs.com/gaochundong/p/mstest_nunit_xunit_comparisons.html

    您的资助是我最大的动力!
    金额随意,欢迎来赏!
    款后有任何问题请给我留言。

    如果,您认为阅读这篇博客让您有些收获,不妨点击一下右下角的推荐按钮。
    如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的关注我。(●'◡'●)

    如果你觉得本篇文章对你有所帮助,请给予我更多的鼓励,求打             付款后有任何问题请给我留言!!!

    因为,我的写作热情也离不开您的肯定支持,感谢您的阅读,我是【Jack_孟】!

  • 相关阅读:
    09不可变类型
    08浅拷贝和深拷贝
    07参数的传递
    06判等对象是否相等
    05引用类型以及特殊引用类型string
    报错:Missing type map configuration or unsupported mapping
    黄聪:VS2010开发T4模版引擎之基础入门
    黄聪:《网站高转换率法则》#2:你的网站是垃圾站吗?
    黄聪:《网站高转换率法则》#1:为什么要研究网站转换率?
    黄聪:百度知道中对HTML字符实体、字符编号,&开头字符的使用
  • 原文地址:https://www.cnblogs.com/mq0036/p/15400859.html
Copyright © 2020-2023  润新知