我想为测试的设置提供参数化数据。类似这样的东西:
[TestCase("1", "2")
[TestCase("a", "b")
public class TestFixture
{
[SetUp]
public void SetUp(string x, string y)
{
Console.WriteLine("Setup with {0}, {1}", x, y);
}
[Test]
public void Test() {...}
}
但我只能设法将参数传递给测试用例本身。
我更喜欢nunit或mbnit [编辑]使用NUnit我可以做到这一点: [/edit] 这似乎符合我的需求,但我会把这个问题留几天,看看是否有其他选择。[TestFixture("1", "2")]
[TestFixture("a", "b")]
public class Tests
{
private string _x;
private string _y;
public Tests(string x, string y)
{
_x = x;
_y = y;
}
[SetUp]
public void SetUp()
{
Console.WriteLine("Setup with {0}, {1}", _x, _y);
}
[Test]
public void Test()
{
}
}
使用NUnit我可以实现以下功能:
[TestFixture("1", "2")]
[TestFixture("a", "b")]
public class Tests
{
private string _x;
private string _y;
public Tests(string x, string y)
{
_x = x;
_y = y;
}
[SetUp]
public void SetUp()
{
Console.WriteLine("Setup with {0}, {1}", _x, _y);
}
[Test]
public void Test()
{
}
}