FortuneN / FineCodeCoverage

Visualize unit test code coverage easily for free in Visual Studio Community Edition (and other editions too)
https://marketplace.visualstudio.com/items?itemName=FortuneNgwenya.FineCodeCoverage
Other
516 stars 39 forks source link

Coverage is not done when XML deserialize called from unit test .Net7 C# #346

Closed mohinimhetre closed 1 year ago

mohinimhetre commented 1 year ago

Installed product versions

Description

Many of my unit test calls XML deserialize system method. Whoever calling it are not getting into coverage.

Steps to recreate

Create unit test and call this code block

using (var reader = new StreamReader(@"..\..\..\Helpers\Event.xml"))
                var @event = (_eventSerializer.Deserialize(reader) as Event)!;

tool is not able to proceed further after deserialize line

Current behavior

After derserialize step tool is not goin further and do code coverage

Expected behavior

It should detect code coverage even after calling deserize of xml.

Side Notes

I am using nunit test .net7.

in below example code coverage is showing red after setup line "GetEvent". GetEvent code is given above description XML file

<Event xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"  Id="123" >
</Event>

Event class

public class Event
{
       [XmlAttribute]
        public int Id { get; set; }
}
    ```

[Test] public void GetLiveEvent_WithPreMatch_ShouldGetError() { // setup var evt = XmlToObjectConverter.GetEvent(); // Act, keeping it blank as it doen't needed to reproduce the issue

       // Assert
       Assert.IsNotNull(evt);
   }
tonyhallett commented 1 year ago

Switch to ms code coverage if you have hard coded paths.