I have a problem with the code coverage of MSTest in my UWP Application.
Every time I try to run a coverage I get this result:
Empty results generated: No binaries were instrumented. Make sure the tests ran, required binaries were loaded, had matching symbol files, and were not excluded through custom settings. For more information see https://go.microsoft.com/fwlink/?LinkID=253731
I have followed all the different troubleshooting things in the link above. But they don't seem to resolve it. I do not know what is causing this but here is some information related to my environment.
References of my Test project:
The *.pdb files of my references are present in the build directory of my Test project.
[TestClass]
public class UnitModelTests
{
[DataTestMethod]
#region Metric
[DataRow(LengthMetric.MM, "1mm", UnitType.Metric)]
[DataRow(LengthMetric.CM - LengthMetric.MM, "9mm", UnitType.Metric)]
[DataRow(LengthMetric.CM, "1cm", UnitType.Metric)]
[DataRow(LengthMetric.DM - LengthMetric.CM, "9cm", UnitType.Metric)]
[DataRow(LengthMetric.DM, "1dm", UnitType.Metric)]
[DataRow(LengthMetric.M - LengthMetric.DM, "9dm", UnitType.Metric)]
[DataRow(LengthMetric.M, "1m", UnitType.Metric)]
[DataRow(LengthMetric.KM - LengthMetric.M, "999m", UnitType.Metric)]
[DataRow(LengthMetric.KM, "1km", UnitType.Metric)]
[DataRow(LengthMetric.KM * 100, "100km", UnitType.Metric)]
#endregion
#region Imperial
[DataRow(LengthImperial.Inch, "1 inch", UnitType.Imperial)]
[DataRow(LengthImperial.Feet, "1 feet", UnitType.Imperial)]
[DataRow(LengthImperial.Yard, "1 yard", UnitType.Imperial)]
[DataRow(LengthImperial.Chain, "1 chain", UnitType.Imperial)]
[DataRow(LengthImperial.Furlong, "1 furlong", UnitType.Imperial)]
[DataRow(LengthImperial.Mile, "1 mile", UnitType.Imperial)]
[DataRow(LengthImperial.League, "1 league", UnitType.Imperial)]
#endregion
public void LengthToStringTest(double startLength, string expected, UnitType unitType)
{
var length = new Length(startLength);
Assert.AreEqual(expected, length.UnitToString(unitType));
}
[DataTestMethod]
#region Metric
[DataRow(VolumeMetric.MM, "1mm^3", UnitType.Metric)]
[DataRow(VolumeMetric.MM * 9, "9mm^3", UnitType.Metric)]
[DataRow(VolumeMetric.CM, "1cm^3", UnitType.Metric)]
[DataRow(VolumeMetric.CM * 9, "9cm^3", UnitType.Metric)]
[DataRow(VolumeMetric.DM, "1dm^3", UnitType.Metric)]
[DataRow(VolumeMetric.DM * 9, "9dm^3", UnitType.Metric)]
[DataRow(VolumeMetric.M, "1m^3", UnitType.Metric)]
[DataRow(VolumeMetric.M * 999, "999m^3", UnitType.Metric)]
[DataRow(VolumeMetric.KM, "1km^3", UnitType.Metric)]
[DataRow(VolumeMetric.KM * 100, "100km^3", UnitType.Metric)]
#endregion
#region Imperial
[DataRow(VolumeImperial.FluidOunce, "1 Fluid ounce", UnitType.Imperial)]
[DataRow(VolumeImperial.Gill, "1 Gill", UnitType.Imperial)]
[DataRow(VolumeImperial.Pint, "1 Pint", UnitType.Imperial)]
[DataRow(VolumeImperial.Quart, "1 Quart", UnitType.Imperial)]
[DataRow(VolumeImperial.Gallon, "1 Gallon", UnitType.Imperial)]
#endregion
public void VolumeToStringTest(double startVolume, string expected, UnitType unitType)
{
var volume = new Volume(startVolume);
Assert.AreEqual(expected, volume.UnitToString(unitType));
}
}
Test Results: All tests that are shown here return as successful.
Build configuration:
NuGet Packages of the MSTest project:
If more information is needed please leave a comment.
The UWP MSTest implementation currently does not support code coverage. Here is a link to a blog that talks about it. A workaround could be to change the UWP Class Libary
to a .NET Standard Class Libary
. Then change the UWP MSTest project
to the .NET Core
variant. After changing this and running the code coverage via test explorer you get the results you wanted.
For a better explanation about this issue, you can visit this website that talks about it. https://www.redgreencode.com/unit-testing-uwp-apps/