这三个测试是相同的,除了它们使用不同的静态函数来创建StartInfo实例。我有这种模式通过我的测试代码,并会喜欢 能够使用[TestCase],或任何其他减少样板代码的方式来简化。据我所知,我不允许使用委托作为[TestCase]的参数,我希望这里的人们对如何使代码更简洁明了有创意。如何简化这些NUNit测试?
[Test]
public void ResponseHeadersWorkinPlatform1()
{
DoResponseHeadersWorkTest(Platform1StartInfo.CreateOneRunning);
}
[Test]
public void ResponseHeadersWorkinPlatform2()
{
DoResponseHeadersWorkTest(Platform2StartInfo.CreateOneRunning);
}
[Test]
public void ResponseHeadersWorkinPlatform3()
{
DoResponseHeadersWorkTest(Platform3StartInfo.CreateOneRunning);
}
void DoResponseHeadersWorkTest(Func<ScriptResource,StartInfo> startInfoCreator)
{
ScriptResource sr = ScriptResource.Default;
var process = startInfoCreator(sr).Start();
//assert some things here
}
教会了我一个新的概念!加+1 – Prashant 2010-05-07 15:58:40
+1不错。这是一个改进的[NUnit文档链接示例](http://nunit.org/index.php?p=testCaseSource&r=2.5.10)。 – 2011-07-25 18:14:06