这三个测试是相同的,只是它们使用不同的静态函数来创建 StartInfo 实例。我的测试代码中都出现了这种模式,并且希望能够使用 [TestCase] 或任何其他减少样板代码的方式来简化它。据我所知,我不允许使用委托作为 [TestCase] 参数,我希望这里的人们对如何使下面的代码更简洁有创意。
[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
}