diff --git a/scripts/build/TestPlatform.Dependencies.props b/scripts/build/TestPlatform.Dependencies.props index 055803abb0..1a5df47c2d 100644 --- a/scripts/build/TestPlatform.Dependencies.props +++ b/scripts/build/TestPlatform.Dependencies.props @@ -37,6 +37,8 @@ $(MicrosoftBuildPackageVersion) $(MicrosoftBuildPackageVersion) 3.0.0-preview4-27615-11 + + 1.2.0 diff --git a/test/Microsoft.TestPlatform.SmokeTests/DataCollectorTests.Coverlet.cs b/test/Microsoft.TestPlatform.SmokeTests/DataCollectorTests.Coverlet.cs new file mode 100644 index 0000000000..b68143fe5e --- /dev/null +++ b/test/Microsoft.TestPlatform.SmokeTests/DataCollectorTests.Coverlet.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.TestPlatform.SmokeTests +{ + using Microsoft.TestPlatform.TestUtilities; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions; + using System; + using System.IO; + using System.Linq; + + [TestClass] + public class DataCollectorTestsCoverlets : IntegrationTestBase + { + [TestMethod] + public void RunCoverletCoverage() + { + // Collector is supported only for netcoreapp2.1, is compiled for netcoreapp2.1 and packaged as netstandard + if (this.testEnvironment.TargetFramework != CoreRunnerFramework) + { + return; + } + + // We use netcoreapp runner + // "...\vstest\tools\dotnet\dotnet.exe "...\vstest\artifacts\Debug\netcoreapp2.1\vstest.console.dll" --collect:"XPlat Code Coverage" ... + this.testEnvironment.RunnerFramework = CoreRunnerFramework; + + string coverletAdapterPath = Path.GetDirectoryName(Directory.GetFiles(this.testEnvironment.GetNugetPackage("coverlet.collector"), "coverlet.collector.dll", SearchOption.AllDirectories).Single()); + string logId = Guid.NewGuid().ToString("N"); + string assemblyPath = this.BuildMultipleAssemblyPath("CoverletCoverageTestProject.dll").Trim('\"'); + string logPath = Path.Combine(Path.GetDirectoryName(assemblyPath), $"coverletcoverage.{logId}.log"); + string logPathDirectory = Path.GetDirectoryName(logPath); + string argument = $"--collect:{"XPlat Code Coverage".AddDoubleQuote()} {PrepareArguments(assemblyPath, coverletAdapterPath, "", ".NETCoreApp,Version=v2.1")} --diag:{logPath.AddDoubleQuote()}"; + this.InvokeVsTest(argument); + + // Verify vstest.console.dll CollectArgumentProcessor fix codeBase for coverlet package + // This assert check that we're sure that we've updated collector setting code base with full path, + // otherwise without "custom coverlet code" inside ProxyExecutionManager coverlet dll won't be resolved inside testhost. + var log = Directory.GetFiles(logPathDirectory, $"coverletcoverage.{logId}.log").Single(); + Assert.IsTrue(File.ReadAllText(log).Contains("CoverletDataCollector in-process codeBase path")); + + // Verify out-of-proc coverlet collector load + var dataCollectorLog = Directory.GetFiles(logPathDirectory, $"coverletcoverage.{logId}.datacollector*log").Single(); + Assert.IsTrue(File.ReadAllText(dataCollectorLog).Contains("[coverlet]Initializing CoverletCoverageDataCollector")); + + // Verify in-proc coverlet collector load + var hostLog = Directory.GetFiles(logPathDirectory, $"coverletcoverage.{logId}.host*log").Single(); + Assert.IsTrue(File.ReadAllText(hostLog).Contains("[coverlet]Initialize CoverletInProcDataCollector")); + + // Verify default coverage file is generated + this.StdOutputContains("coverage.cobertura.xml"); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs index 724dea78ed..4c66e371c6 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs @@ -527,7 +527,7 @@ private void ExecutePatchedDotnet(string command, string args, out string stdOut ["DOTNET_MULTILEVEL_LOOKUP"] = "0" }; - var patchedDotnetPath = Path.Combine(this.testEnvironment.TestArtifactsDirectory, @"dotnet\dotnet.exe"); ; + var patchedDotnetPath = Path.Combine(this.testEnvironment.TestArtifactsDirectory, @"dotnet\dotnet.exe"); this.ExecuteApplication(patchedDotnetPath, string.Join(" ", command, args), out stdOut, out stdError, out exitCode, environmentVariables); } diff --git a/test/TestAssets/CoverletCoverageTestProject/CoverletCoverageTestProject.csproj b/test/TestAssets/CoverletCoverageTestProject/CoverletCoverageTestProject.csproj new file mode 100644 index 0000000000..20078ca91b --- /dev/null +++ b/test/TestAssets/CoverletCoverageTestProject/CoverletCoverageTestProject.csproj @@ -0,0 +1,19 @@ + + + + + + + + netcoreapp2.1 + false + + + + + + + + + + \ No newline at end of file diff --git a/test/TestAssets/CoverletCoverageTestProject/UnitTest1.cs b/test/TestAssets/CoverletCoverageTestProject/UnitTest1.cs new file mode 100644 index 0000000000..7183e4941d --- /dev/null +++ b/test/TestAssets/CoverletCoverageTestProject/UnitTest1.cs @@ -0,0 +1,13 @@ +using Xunit; + +namespace CoverletCoverageTestProject +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + + } + } +} diff --git a/test/TestAssets/TestAssets.sln/TestAssets.sln b/test/TestAssets/TestAssets.sln/TestAssets.sln index e09a9e28e7..a137da29f3 100644 --- a/test/TestAssets/TestAssets.sln/TestAssets.sln +++ b/test/TestAssets/TestAssets.sln/TestAssets.sln @@ -68,6 +68,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleProjectWithOldTestHos EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleClassLibrary", "..\SimpleClassLibrary\SimpleClassLibrary.csproj", "{F37144D7-2C6D-42AF-9E85-EF10E5244A7B}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoverletCoverageTestProject", "..\CoverletCoverageTestProject\CoverletCoverageTestProject.csproj", "{0D4D59D7-C52F-4858-A220-EAC7484E3827}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -438,6 +440,18 @@ Global {F37144D7-2C6D-42AF-9E85-EF10E5244A7B}.Release|x64.Build.0 = Release|Any CPU {F37144D7-2C6D-42AF-9E85-EF10E5244A7B}.Release|x86.ActiveCfg = Release|Any CPU {F37144D7-2C6D-42AF-9E85-EF10E5244A7B}.Release|x86.Build.0 = Release|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Debug|x64.ActiveCfg = Debug|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Debug|x64.Build.0 = Debug|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Debug|x86.ActiveCfg = Debug|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Debug|x86.Build.0 = Debug|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Release|Any CPU.Build.0 = Release|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Release|x64.ActiveCfg = Release|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Release|x64.Build.0 = Release|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Release|x86.ActiveCfg = Release|Any CPU + {0D4D59D7-C52F-4858-A220-EAC7484E3827}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE