Search code examples
unit-testingtestingtfsbuildexpected-exception

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


I try to automate some unit tests with our TFS build process and some tests results have this error: "The agent process was stopped while the test was running."

All of them have the "ExpectedException" attribute. For example:

    [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");
    }

When I run these tests from the Test Explorer, the results are "Test passed". But when they are executed from the build, they ends up with the previous error.

Why is this happening? How can I fix it?

Thanks.


Solution

  • I found what caused the error!

    I had one try-catch with next sentence in the catch region:

    Debugger.Break();
    

    I delete this line and now all test results are OK.