有什么方法可以断言该方法的正确行为吗?

时间:2019-05-23 09:06:11

标签: c# .net unit-testing

我有一种方法需要测试其所有分支。 我找不到断言或验证测试正确的方法,因为两个分支的行为几乎相同。 顺便说一句-我无法更改给定的代码

我尝试验证End和Write是否被调用,但在两种情况下都被调用。

if (m_FailedOnInitialize)
{
    if (!ctx.Request.IsLocal)
    {
        ctx.Response.Write("Failed on initialization");
        ctx.Response.End();
    }
    else
    {      
        ctx.Response.Write(m_FirstError.ToString());
        ctx.Response.End();
    }
}

m_FailedOnInitialize是一个static字段,我将其设置为true
在每次测试中,ctx.Request.IsLocal设置为true \ false。

要断言我使用Typemock的验证

Isolate.Verify.WasCalled(() => ctx.Response.write(""));
Isolate.Verify.WasNotCalled(() => ctx.Response.End());

0 个答案:

没有答案
相关问题