Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable code coverage when "Code Coverage;arg1=val1;arg2=val2" is provided in cli #3172

Merged
merged 14 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding test for overriding format from settings file using collect co…
…mmand,
  • Loading branch information
fhnaseer committed Nov 12, 2021
commit 0cee134fe33399cce7fa58cd3aa1aa4680146b0c
15 changes: 8 additions & 7 deletions scripts/vstest-codecoverage2.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0">
<Configuration>
<CodeCoverage>
<!-- Match assembly file paths: -->
<Format>Coverage</Format>
<CodeCoverage>
<!-- Match assembly file paths: -->
<ModulePaths>
<Exclude>
<ModulePath>.*CodeCoverage.exe$</ModulePath>
Expand All @@ -17,11 +18,11 @@
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>

<Functions>
<Exclude>
<Function>.*TestSign.*</Function>
</Exclude>
</Functions>
<Functions>
<Exclude>
<Function>.*TestSign.*</Function>
</Exclude>
</Functions>

</CodeCoverage>
</Configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ protected XmlNode GetModuleNode(XmlNode node, string name)
if (moduleNode == null)
{
moduleNode = this.GetNode(node, "package", name);

if (moduleNode == null)
{
moduleNode = this.GetNode(node, "package", Path.GetFileNameWithoutExtension(name));
}
}

return moduleNode;
Expand Down
25 changes: 20 additions & 5 deletions test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,15 @@ public void CollectCodeCoverageSpecifyOutputFormatXml(RunnerInfo runnerInfo)
[TestMethod]
[NetFullTargetFrameworkDataSource(useDesktopRunner: false)]
[NetCoreTargetFrameworkDataSource(useDesktopRunner: false)]
public void CollectCodeCoverageSpecifyOutputFormatCobertura(RunnerInfo runnerInfo)
public void CollectCodeCoverageSpecifyOutputFormatCoberturaOverrideRunSettingsConfiguration(RunnerInfo runnerInfo)
{
var parameters = new TestParameters()
{
AssemblyName = "SimpleTestProject.dll",
TargetPlatform = "x64",
RunSettingsPath = string.Empty,
RunSettingsPath = Path.Combine(
IntegrationTestEnvironment.TestPlatformRootDirectory,
@"scripts", "vstest-codecoverage2.runsettings"),
RunSettingsType = TestParameters.SettingsType.CoberturaOutput,
ExpectedPassedTests = 1,
ExpectedSkippedTests = 1,
Expand Down Expand Up @@ -244,7 +246,7 @@ private void CollectCodeCoverage(RunnerInfo runnerInfo, TestParameters testParam
this.AssertSkippedMethod(coverageDocument);
}

this.ValidateCoverageData(coverageDocument, testParameters.AssemblyName);
this.ValidateCoverageData(coverageDocument, testParameters.AssemblyName, testParameters.RunSettingsType != TestParameters.SettingsType.CoberturaOutput);

Directory.Delete(this.resultsDirectory, true);
}
Expand Down Expand Up @@ -287,9 +289,17 @@ private string CreateArguments(
break;
case TestParameters.SettingsType.XmlOutput:
runSettings = $" /collect:\"Code Coverage;Format=Xml\"";
if (!string.IsNullOrWhiteSpace(testParameters.RunSettingsPath))
{
runSettings += $" /settings:{testParameters.RunSettingsPath}";
}
break;
case TestParameters.SettingsType.CoberturaOutput:
runSettings = $" /collect:\"Code Coverage;Format=Cobertura\"";
if (!string.IsNullOrWhiteSpace(testParameters.RunSettingsPath))
{
runSettings += $" /settings:{testParameters.RunSettingsPath}";
}
break;
}

Expand Down Expand Up @@ -318,7 +328,7 @@ private void AssertSkippedMethod(XmlDocument document)
Assert.IsNotNull(testAbsFunction);
}

private void ValidateCoverageData(XmlDocument document, string moduleName)
private void ValidateCoverageData(XmlDocument document, string moduleName, bool validateSourceFileNames)
{
var module = this.GetModuleNode(document.DocumentElement, moduleName.ToLower());

Expand All @@ -329,7 +339,12 @@ private void ValidateCoverageData(XmlDocument document, string moduleName)
Assert.IsNotNull(module);

this.AssertCoverage(module, CodeCoverageAcceptanceTestBase.ExpectedMinimalModuleCoverage);
this.AssertSourceFileName(module);

// In case of cobertura report. Cobertura report has different format.
if (validateSourceFileNames)
{
this.AssertSourceFileName(module);
}
}

private void AssertSourceFileName(XmlNode module)
Expand Down