Skip to content

Add examples on guide #540

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

Merged
merged 6 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>
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