Skip to content
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
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Imports Common TestAssets props. -->
<Import Project="..\..\..\scripts\build\TestAssets.props" />
<Import Project="..\..\..\scripts\build\TestPlatform.Dependencies.props" />
<!-- Package dependency versions -->

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(NETTestSdkVersion)" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions test/TestAssets/CoverletCoverageTestProject/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Xunit;

namespace CoverletCoverageTestProject
{
public class UnitTest1
{
[Fact]
public void Test1()
{

}
}
}
14 changes: 14 additions & 0 deletions test/TestAssets/TestAssets.sln/TestAssets.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down