【发布时间】:2008-10-22 04:11:24
【问题描述】:
我正在使用 Microsoft WebTest,并且希望能够执行类似于 NUnit 的 Assert.Fail() 的操作。我想出的最好的方法是throw new webTestException(),但这在测试结果中显示为Error,而不是Failure。
除了反映WebTest 设置一个私有成员变量来指示失败之外,我还有什么遗漏的吗?
编辑:我也使用了 Assert.Fail() 方法,但是在 WebTest 中使用时这仍然显示为错误而不是失败,并且 Outcome 属性是只读的(没有公共设置器)。
编辑:现在我真的很难过。我使用反射将Outcome 属性设置为失败,但测试仍然通过!
以下是将 Oucome 设置为失败的代码:
public static class WebTestExtensions
{
public static void Fail(this WebTest test)
{
var method = test.GetType().GetMethod("set_Outcome", BindingFlags.NonPublic | BindingFlags.Instance);
method.Invoke(test, new object[] {Outcome.Fail});
}
}
这是我试图失败的代码:
public override IEnumerator<WebTestRequest> GetRequestEnumerator()
{
this.Fail();
yield return new WebTestRequest("http://google.com");
}
Outcome 被设置为 Oucome.Fail,但显然 WebTest 框架并没有真正使用它来确定测试通过/失败结果。
【问题讨论】:
标签: c# unit-testing mstest webtest