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

Update fork #3

Merged
merged 4 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Documentation/Examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Examples

## MSBuild Integration
* Use `/p:MergeWith` feature `Documentation/Examples/MSBuild/MergeWith/MergeWith.sln`
12 changes: 12 additions & 0 deletions Documentation/Examples/MSBuild/MergeWith/ClassLibrary1/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace ClassLibrary1
{
public class Class1
{
public int Method()
{
return 42;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions Documentation/Examples/MSBuild/MergeWith/ClassLibrary2/Class2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace ClassLibrary2
{
public class Class2
{
public int Method()
{
return 42;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions Documentation/Examples/MSBuild/MergeWith/ClassLibrary3/Class3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace ClassLibrary3
{
public class Class3
{
public int Method()
{
return 42;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

</Project>
10 changes: 10 additions & 0 deletions Documentation/Examples/MSBuild/MergeWith/MergeWith.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**Run from solution root sln**

To merge report togheter you need to run separate test and merge in one `json` format file.
Last command will join and create final needed format file.

```
dotnet test XUnitTestProject1\XUnitTestProject1.csproj /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/
dotnet test XUnitTestProject2\XUnitTestProject2.csproj /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json"
dotnet test XUnitTestProject3\XUnitTestProject3.csproj /p:CollectCoverage=true /p:CoverletOutput=../CoverageResults/ /p:MergeWith="../CoverageResults/coverage.json" /p:CoverletOutputFormat="opencover"
```
60 changes: 60 additions & 0 deletions Documentation/Examples/MSBuild/MergeWith/MergeWith.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29230.61
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{4B6E5DCB-C16F-4880-AA97-BC5D01959E49}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitTestProject1", "XUnitTestProject1\XUnitTestProject1.csproj", "{39597E4B-23B4-4A6A-A71B-FFBE131A94D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary2", "ClassLibrary2\ClassLibrary2.csproj", "{973ECB19-5301-4191-9D93-3BEC9D2FCCF6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitTestProject2", "XUnitTestProject2\XUnitTestProject2.csproj", "{6ED65535-CCC9-438E-80D4-1598FB572512}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5F5E20F4-E34C-48BB-906D-65CF1B55A6AA}"
ProjectSection(SolutionItems) = preProject
MergeWith.md = MergeWith.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary3", "ClassLibrary3\ClassLibrary3.csproj", "{2443A7B5-99D5-40EA-9501-CCE80FC8951A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XUnitTestProject3", "XUnitTestProject3\XUnitTestProject3.csproj", "{FE26E5E2-B692-4FF2-86BE-E3E3DC44DA23}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4B6E5DCB-C16F-4880-AA97-BC5D01959E49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B6E5DCB-C16F-4880-AA97-BC5D01959E49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B6E5DCB-C16F-4880-AA97-BC5D01959E49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B6E5DCB-C16F-4880-AA97-BC5D01959E49}.Release|Any CPU.Build.0 = Release|Any CPU
{39597E4B-23B4-4A6A-A71B-FFBE131A94D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39597E4B-23B4-4A6A-A71B-FFBE131A94D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39597E4B-23B4-4A6A-A71B-FFBE131A94D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39597E4B-23B4-4A6A-A71B-FFBE131A94D6}.Release|Any CPU.Build.0 = Release|Any CPU
{973ECB19-5301-4191-9D93-3BEC9D2FCCF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{973ECB19-5301-4191-9D93-3BEC9D2FCCF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{973ECB19-5301-4191-9D93-3BEC9D2FCCF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{973ECB19-5301-4191-9D93-3BEC9D2FCCF6}.Release|Any CPU.Build.0 = Release|Any CPU
{6ED65535-CCC9-438E-80D4-1598FB572512}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6ED65535-CCC9-438E-80D4-1598FB572512}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6ED65535-CCC9-438E-80D4-1598FB572512}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6ED65535-CCC9-438E-80D4-1598FB572512}.Release|Any CPU.Build.0 = Release|Any CPU
{2443A7B5-99D5-40EA-9501-CCE80FC8951A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2443A7B5-99D5-40EA-9501-CCE80FC8951A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2443A7B5-99D5-40EA-9501-CCE80FC8951A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2443A7B5-99D5-40EA-9501-CCE80FC8951A}.Release|Any CPU.Build.0 = Release|Any CPU
{FE26E5E2-B692-4FF2-86BE-E3E3DC44DA23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE26E5E2-B692-4FF2-86BE-E3E3DC44DA23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE26E5E2-B692-4FF2-86BE-E3E3DC44DA23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE26E5E2-B692-4FF2-86BE-E3E3DC44DA23}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1D8D22CA-6A4F-4F12-87D2-62754F69FF39}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Xunit;

namespace XUnitTestProject1
{
public class UnitTest1
{
[Fact]
public void Test1()
{
new ClassLibrary1.Class1().Method();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.6.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Xunit;

namespace XUnitTestProject2
{
public class UnitTest2
{
[Fact]
public void Test2()
{
new ClassLibrary2.Class2().Method();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.6.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ClassLibrary2\ClassLibrary2.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Xunit;

namespace XUnitTestProject3
{
public class UnitTest3
{
[Fact]
public void Test3()
{
new ClassLibrary3.Class3().Method();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.6.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ClassLibrary3\ClassLibrary3.csproj" />
</ItemGroup>

</Project>
81 changes: 79 additions & 2 deletions Documentation/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Hits file:'C:\Users\Marco\AppData\Local\Temp\coverlet.core_703263e9-21f0-4d1c-9c
+---------+--------+--------+--------+
```

## Use local build
## Use local build(no collectors)

Sometimes is useful test local updated source to fix issue.
You can "load" your local build using simple switch:
Expand Down Expand Up @@ -110,4 +110,81 @@ Test run for D:\git\Cake.Codecov\Source\Cake.Codecov.Tests\bin\Debug\netcoreapp2
...
```

In this way you can add `Debug.Launch()` inside coverlet source and debug.
In this way you can add `Debug.Launch()` inside coverlet source and debug.

## Use local collectors build

To use/debug local collectors build we need to tell to our project to restore and use our local build nuget package.

1) Build local package
```
C:\git\coverlet\src\coverlet.collector (master -> origin)
λ dotnet pack
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Restore completed in 50,28 ms for C:\git\coverlet\src\coverlet.collector\coverlet.collector.csproj.
Restore completed in 50,28 ms for C:\git\coverlet\src\coverlet.core\coverlet.core.csproj.
coverlet.core -> C:\git\coverlet\src\coverlet.core\bin\Debug\netstandard2.0\coverlet.core.dll
coverlet.collector -> C:\git\coverlet\src\coverlet.collector\bin\Debug\netcoreapp2.0\coverlet.collector.dll
Successfully created package 'C:\git\coverlet\bin\Debug\Packages\coverlet.collector.1.0.67.nupkg'.
Successfully created package 'C:\git\coverlet\bin\Debug\Packages\coverlet.collector.1.0.67.snupkg'.
```
2) Add new `NuGet.Config` file on your test project/solution
```
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<!-- Local path where you build packages -->
<add key="localpackagesbuild" value="C:\git\coverlet\bin\Debug\Packages" />
<!-- Defaul nuget feed -->
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<!-- Add all other needed feed -->
</packageSources>
</configuration>
```
3) Update nuget package in our test project
```xml
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.67" /> <-- My local package version
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />
</ItemGroup>

</Project>

```
4) Run test command
```
dotnet test XUnitTestProject1\ --collect:"XPlat Code Coverage"
```

You can also attach/debug your code adding some line of code on collectors i.e.

Attach using vs "Attach to Process"
```cs
while(!System.Diagnostics.Debugger.IsAttached)
{
System.Threading.Thread.Sleep(1000);
}
```

Fire attach
```cs
System.Diagnostics.Debugger.Launch();
```

**Every time you update code and rebuild new package remember to remove local nuget cache(`RMDIR "C:\Users\[winUser]\.nuget\packages\coverlet.collector" /S /Q`) otherwise you'll load old collector code because the package version wasn't changed**
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Coverlet generates code coverage information by going through the following proc

_Note: The assembly you'd like to get coverage for must be different from the assembly that contains the tests_

## Are you in trouble with some feature? Check on [examples](Documentation/Examples.md)!

## Cake Add-In

If you're using [Cake Build](https://cakebuild.net) for your build script you can use the [Cake.Coverlet](https://github.com/Romanx/Cake.Coverlet) add-in to provide you extensions to dotnet test for passing Coverlet arguments in a strongly typed manner.
Expand Down
2 changes: 1 addition & 1 deletion build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
steps:
- task: UseDotNet@2
inputs:
version: 2.2.300
version: 2.2.401
displayName: Install .NET Core SDK

- script: dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "2.2.300"
"version": "2.2.401"
}
}
4 changes: 3 additions & 1 deletion src/coverlet.collector/DataCollection/CoverageWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Coverlet.Collector.Utilities.Interfaces;
using Coverlet.Core;
using Coverlet.Core.Abstracts;
using Coverlet.Core.Logging;

namespace Coverlet.Collector.DataCollection
Expand Down Expand Up @@ -28,7 +29,8 @@ public Coverage CreateCoverage(CoverletSettings settings, ILogger coverletLogger
settings.SingleHit,
settings.MergeWith,
settings.UseSourceLink,
coverletLogger);
coverletLogger,
(IInstrumentationHelper)DependencyInjection.Current.GetService(typeof(IInstrumentationHelper)));
}

/// <summary>
Expand Down
Loading