diff --git a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs index 2d151decb3..2ded9cc953 100644 --- a/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs +++ b/src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs @@ -20,6 +20,7 @@ public class VSTestTask : Task, ICancelableTask private VSTestForwardingApp vsTestForwardingApp; private const string vsTestAppName = "vstest.console.dll"; + private const string CodeCovergaeString = "Code Coverage"; public string TestFileFullPath { @@ -368,7 +369,12 @@ private List AddArgs() { foreach (var arg in this.VSTestCollect) { - if (arg.Equals("Code Coverage", StringComparison.OrdinalIgnoreCase)) + // For collecting code coverage, argument value can be either "Code Coverage" or "Code Coverage;a=b;c=d". + // Split the argument with ';' and compare first token value. + var tokens = arg.Split(';'); + + if (arg.Equals(CodeCovergaeString, StringComparison.OrdinalIgnoreCase) || + tokens[0].Equals(CodeCovergaeString, StringComparison.OrdinalIgnoreCase)) { isCollectCodeCoverageEnabled = true; } diff --git a/test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs b/test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs index e3ddc98587..c61451ec9a 100644 --- a/test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs +++ b/test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs @@ -266,6 +266,19 @@ public void CreateArgumentShouldAddTraceCollectorDirectoryPathAsTestAdapterForCo CollectionAssert.Contains(allArguments, expectedArg, $"Expected argument: '''{expectedArg}''' not present in [{string.Join(", ", allArguments)}]"); } + [TestMethod] + public void CreateArgumentShouldAddTraceCollectorDirectoryPathAsTestAdapterForCodeCoverageCollectWithExtraConfigurations() + { + const string traceDataCollectorDirectoryPath = @"c:\path\to\tracedata collector"; + this.vsTestTask.VSTestTraceDataCollectorDirectoryPath = traceDataCollectorDirectoryPath; + this.vsTestTask.VSTestCollect = new string[] { "code coverage;someParameter=someValue" }; + + var allArguments = this.vsTestTask.CreateArgument().ToArray(); + + const string expectedArg = "--testAdapterPath:\"c:\\path\\to\\tracedata collector\""; + CollectionAssert.Contains(allArguments, expectedArg, $"Expected argument: '''{expectedArg}''' not present in [{string.Join(", ", allArguments)}]"); + } + [TestMethod] public void CreateArgumentShouldNotAddTraceCollectorDirectoryPathAsTestAdapterForNonCodeCoverageCollect() {