How to cover exceptions in Visual Code Code Coverage

I'm new to code coverage, and I'm trying to get my unit tests to cover% 100 of my code.

My first question is: is this possible / possible?

My second, more specific question: I have the following method:

/// <summary>
/// Clears frames, control groups, display groups
/// </summary>
public bool Clear()
{
    try
    {
        this.Frames.Clear();
        this.ControlGroups.Clear();
        this.DisplayGroups.Clear();
        return true;
    }
    catch (Exception ex)
    {
        Milltown.MTCore.mtException mtEx = new Milltown.MTCore.mtException((int)PFExceptions.Exception_Hidden_FuctionLevel, ex,
        PFCommonVariables.ApplicationPlatform, PFCommonVariables.ApplicationDataSource, "PFSystem:Clear");
        return false;
    }

}

My unit test for this method:

//System Clear Test
Assert.IsTrue(MySystem.Clear());
Assert.AreEqual(0,MySystem.Frames.Count);
Assert.AreEqual(0,MySystem.ControlGroups.Count);
Assert.AreEqual(0, MySystem.DisplayGroups.Count);

The code coverage shows that I cover the lines inside the try block, but not the catch block. How can I cover code in catch blocks?

+3
source share
2 answers

- . 100% - : . , , 100% (. http://nedbatchelder.com/blog/200710/flaws_in_coverage_measurement.html Python). 5% , .

, . , , , .

+2
+2

Source: https://habr.com/ru/post/1755373/


All Articles