【问题标题】:Nunit method and class attribute declaration difference of [Test] and [Test()] [duplicate][Test]和[Test()]的Nunit方法和类属性声明的区别[重复]
【发布时间】:2016-11-25 02:17:14
【问题描述】:

您好,我正在使用 nunit 进行自动化。 我有疑问。

[TestFixture()]
    public class LoginTest
    {
        [Test()]
        public void setup() 
        {
            //setup code
        }
}

[TestFixture]
public class LoginTest
{
    [Test]
    public void setup() 
    {
        //setup code
    }
}

[TextFixture][TextFixture()]有什么区别。

两者似乎都有效。 那么哪种方法是正确的呢?

【问题讨论】:

  • 没有区别。因为 Attribute 是一个类,所以您可以使用括号对其进行实例化。但它们不是必需的,因为它是推断出来的
  • 如果您为属性提供了一些参数,则需要它们

标签: c# unit-testing testing automation nunit


【解决方案1】:

你可以省略它们,没有区别。 事实上,你有 4 种方式来编写完全相同的属性:

[TestFixture]
[TestFixture()]
[TestFixtureAttribute]
[TestFixtureAttribute()]

【讨论】:

    猜你喜欢
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 2012-12-03
    • 1970-01-01
    • 2021-12-04
    • 2012-02-21
    相关资源
    最近更新 更多