1

using Visual Studio 17.14.18

I'm asking Visual Studio to give me a code coverage report, which it does. But there are lots of methods being used by the completed / passing tests that are not included in the report or highlighted as passing.

It's odd because these overlooked methods are in the same classes as other methods that are also getting called but are getting picked up the code coverage reports.

In this case the Read method is getting highlights and inclusion in the code coverage report. But the two write methods are not. The only thing that appears to be different is that two write methods are returning Tuples and the Read isn't.

public void LogEvent() { XX.Data.EventLogs.Interactions.Events.Purge(); DateTime EventDTG = DateTime.Now; Guid EventGUID = Guid.NewGuid(); Guid TransactionGUID = Guid.NewGuid(); string Program = "SYSTEM"; int EventID = 999999; String Subject = "Event Subject"; String Description = "Event Description"; String Notes = "Event Notes"; var t = XX.Universalis.Logging.Write(EventDTG, EventGUID, TransactionGUID, Program, EventID, Subject, Description, Notes); Assert.IsTrue(t.Result == true); Assert.IsTrue(t.IDNumber > 0); XX.Data.EventLogs.Models.Events TheEvent = XX.Universalis.Logging.Read(t.IDNumber); // Can't figure out how to test if the date is correct. // Assert.IsTrue(DateTime.TryParse(TheEvent.DTGCreated, out _)); Assert.IsTrue(TheEvent.EventID == 999999); Assert.IsTrue(TheEvent.Program == "SYSTEM"); Assert.IsTrue(TheEvent.Subject == "Event Subject"); Assert.IsTrue(TheEvent.Description == "Event Description"); Assert.IsTrue(TheEvent.Notes == "Event Notes"); Assert.IsTrue(Guid.TryParse(TheEvent.TransactionGUID.ToString(), out _)); Assert.IsTrue(Guid.TryParse(TheEvent.EventGUID.ToString(), out _)); } 

namespace XX.Universalis { public static class Logging { public static (bool Result, int IDNumber) Write(DateTime DTGCreated, Guid EventGUID, Guid TransactionGUID, string Program, int EventID, string Title, string Description, string Notes) { var t = XX.Data.EventLogs.Interactions.Events.Write(DTGCreated, EventGUID, TransactionGUID, Program, EventID, Title, Description, Notes); return (t.Result, t.IDNumber); } public static (bool Result, int IDNumber) Write(DateTime DTGCreated, Guid EventGUID, Guid TransactionGUID, string Program, int EventID, string Subject, string Description, string Notes, Exception ex) { var t = XX.Data.EventLogs.Interactions.Events.Write(DTGCreated, EventGUID, TransactionGUID, Program, EventID, Subject, Description, Notes, ex); return (t.Result, t.IDNumber); } public static XX.Data.EventLogs.Models.Events Read(int IDNumber) { var context = new XX.Data.EventLogs.EFContext.EventLogsContext(); return context.Events.Where(b => b.IDNumber == IDNumber).ToList().FirstOrDefault(); } 

Here are my TestSettings

<?xml version="1.0" encoding="utf-8"?> <!-- File name extension must be .runsettings --> <RunSettings> <DataCollectionRunSettings> <DataCollectors> <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <Configuration> <CodeCoverage> <!-- Match fully qualified names of functions: --> <!-- (Use "\." to delimit namespaces in C# or Visual Basic, "::" in C++.) --> <Functions> <Exclude> <!-- Testing--> <Function>Microsoft\..*</Function> <Function>System\..*</Function> <Function>TestFx\..*</Function> <Function>System\..*</Function> <Function>XX.UnitTests\..*</Function> <!-- Data Models and EFContext--> <Function>XX.Data.ClientManagement.EFContext\..*</Function> <Function>XX.Data.ClientManagement.Models\..*</Function> <Function>XX.Data.Connie.EFContext\..*</Function> <Function>XX.Data.Connie.Models\..*</Function> <Function>XX.Data.EventLogs.EFContext\..*</Function> <Function>XX.Data.EventLogs.Models\..*</Function> <Function>XX.Data.Medici.EFContext\..*</Function> <Function>XX.Data.Medici.Models\..*</Function> <Function>XX.Data.Sales.EFContext\..*</Function> <Function>XX.Data.Sales.Models\..*</Function> </Exclude> </Functions> </CodeCoverage> </Configuration> </DataCollector> </DataCollectors> </DataCollectionRunSettings> </RunSettings> 

2 Answers 2

0

Here's what's happening

Your test calls XX.Universalis.Logging.Write().

That Write() calls into XX.Data.EventLogs.Interactions.Events.Write().

But your code coverage excludes everything under XX.Data.EventLogs.*, including Models, EFContext, and probably Interactions if it sits under that namespace.

So the coverage collector never tracks those calls, even if they run.

In your .runsettings, remove or adjust the exclude patterns so the Interactions namespace is not filtered out.

Example

<Function>XX.Data.EventLogs.EFContext\..*</Function> <Function>XX.Data.EventLogs.Models\..*</Function> <!-- Remove this if it exists --> <!-- <Function>XX.Data.EventLogs.Interactions\..*</Function> --> 

Then rerun tests with coverage.

You'll see your Write() methods now included and highlighted.

The tuple return type isn't the problem, the namespace exclusion is.

Sign up to request clarification or add additional context in comments.

1 Comment

Doesn't seem to be the answer. The exclude statements cover Data.EventLogs.EFContext & Data.EventLogs.Models - The code that's only partially getting covered is in Data.EventLogs.Interactions.Events Removing EFContext and Models exclude statements from runsettings altogether doesn't fix the problem either. Again it's only doing code coverage reporting on some of the methods in Data.EventLogs.Interactions.Events even though I can see by stepping through that it's getting called. Also the methods getting reported have green checkmarks 1/1 - the ones that aren't getting reported don'
0

OK. The problem was in the Exclude settings, but not where you might expect. I had excluded System.* to get rid of some MSTest namespaces that were showing up in the code coverage reports. I removed the System.* exclude entry and it fixed the problem. I then looked into the report and decided to exclude System.Text and System.IO instead of System.**
*
That solved the problem. I guess there was something in System.* that was inadvertently excluding those two tests that weren't showing up.

 <Function>Microsoft\..*</Function> <Function>System.Text\..*</Function> <Function>System.IO\..*</Function> <Function>TestFx\..*</Function> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.