【发布时间】: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