【发布时间】:2015-03-04 15:38:16
【问题描述】:
我想为测试的设置提供参数化数据。像这样的:
[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 或 mbunit 的解决方案,但对替代方案持开放态度(尚未确定要使用哪个测试框架)。这最终适用于一组 Selenium 系统测试,其中设置会创建一个浏览器会话。
[编辑] 使用 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()
{
}
}
[/编辑]
这似乎符合我的需要,但我会将这个问题留待几天,看看是否建议了替代方案。
【问题讨论】:
标签: nunit automated-tests fixtures mbunit