Tests with expected exception results with the following error: "The agent process was stopped while the test was running."

Tests with expected exception results with the following error: "The agent process was stopped while the test was running."

我尝试使用我们的 TFS 构建过程自动执行一些单元测试,但一些测试结果出现此错误:"The agent process was stopped while the test was running."

它们都具有 "ExpectedException" 属性。例如:

    [ExpectedException(typeof(SuEnlaceModelException))]
    public void SuEnlaceModelParser_ParseDatesError_MonthIsNotANumber()
    {
        var testingDatesFakeModel = new TestingDatesFakeModel();
        SuEnlaceModelParser.ParseLine(testingDatesFakeModel, "x", "2014no01");
        Assert.Fail("Exception must be thrown before reaching this Assert");
    }

当我从 Test Explorer 运行 这些测试时,结果是 "Test passed"。但是当它们从构建中执行时,它们以先前的错误结束。

为什么会这样?我该如何解决?

谢谢。

我找到了导致错误的原因!

我在捕捉区尝试捕捉下一句:

Debugger.Break();

我删除了这一行,现在所有测试结果都OK了。