【问题标题】:What is the pendant of NUnit TestCaseAttribute for MS Test [duplicate]MS Test的NUnit TestCaseAttribute的挂件是什么[重复]
【发布时间】:2015-09-10 17:24:25
【问题描述】:

MS Test 的 NUnit TestCaseAttribute 的挂件是什么?

查看此示例:

[TestCase("Authorization", "Basic", "test@gmail.com:Mypassword", HttpStatusCode.OK)]
[TestCase("Authorization", "bASic", "test@gmail.com:Mypassword", HttpStatusCode.OK)]
[TestCase("WrongAuthorization", "Basic", "test@gmail.com:Mypassword", HttpStatusCode.Unauthorized)]
[TestCase("Authorization", "WrongBasic", "test@gmail.com:Mypassword", HttpStatusCode.Unauthorized)]
[TestCase("Authorization", "Basic", "test@gmail.com:Mypassword:anotherpassword", HttpStatusCode.Unauthorized)]
[TestCase("Authorization", "Basic", "", HttpStatusCode.Unauthorized)]
[TestCase("test", "", "test@gmail.com:Mypassword", HttpStatusCode.Unauthorized)]
public void Authenticate_User(string headerName, string headerValue, string credentials, HttpStatusCode expectedStatusCode)
{
    // Arrange
    var encodedEmailPassword = Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials));
    _client.DefaultRequestHeaders.Add(headerName, headerValue + " " + encodedEmailPassword);

    // Act
    var response = _client.SendAsync(new HttpRequestMessage(HttpMethod.Post, _server.BaseAddress + "api/authentication")).Result;

    // Assert
    Assert.That(response.StatusCode == expectedStatusCode);
}

【问题讨论】:

  • 查看RowTest,或者,更好的是,避免 MS 测试。另外:nuget.org/packages/MSTestHacks
  • 我查找了 RowTest,发现了一堆非常古老的令人困惑的链接!
  • @DariuszWoźniak Dude...这个链接已有 6 年历史了我为什么要关心?

标签: c# unit-testing nunit mstest data-driven-tests


【解决方案1】:

TestCase 属性使用提供的参数运行方法。 Authenticate_User 将使用不同的参数运行 7 次。

更多关于NUnit TestCase的信息http://www.nunit.org/index.php?p=testCase&r=2.5

另见Does MSTest have an equivalent to NUnit's TestCase?

【讨论】:

    猜你喜欢
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多