[testing/dotnet] Support gathering coverage data.

Use the `coverlet` collector to gather and report coverage data.
Coverage is only gathered and reported if the
`PULUMI_TEST_COVERAGE_PATH` environment variable is set.
This commit is contained in:
Pat Gavlin 2021-10-19 10:59:11 -07:00
parent 96746ddeab
commit 008ac014d4
2 changed files with 12 additions and 2 deletions

View file

@ -18,6 +18,12 @@ ensure::
# We want to dotnet restore all projects on startup so that omnisharp doesn't complain about lots of missing types on startup.
dotnet restore dotnet.sln
ifneq ($(PULUMI_TEST_COVERAGE_PATH),)
TEST_COVERAGE_ARGS := /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(PULUMI_TEST_COVERAGE_PATH)
else
TEST_COVERAGE_ARGS := /p:CollectCoverage=false /p:CoverletOutput=$(PULUMI_TEST_COVERAGE_PATH)
endif
build::
# From the nuget docs:
#
@ -45,11 +51,11 @@ install:: build install_plugin
dotnet_test:: $(TEST_ALL_DEPS)
# include the version prefix/suffix to avoid generating a separate nupkg file
$(RUN_TESTSUITE) dotnet-test dotnet test --no-build --filter --filter FullyQualifiedName\\!~Pulumi.Automation.Tests /p:Version=${DOTNET_VERSION}
$(RUN_TESTSUITE) dotnet-test dotnet test --no-build --filter FullyQualifiedName\!~Pulumi.Automation.Tests /p:Version=${DOTNET_VERSION} ${TEST_COVERAGE_ARGS}/dotnet.xml
auto_test:: $(TEST_ALL_DEPS)
# include the version prefix/suffix to avoid generating a separate nupkg file
$(RUN_TESTSUITE) auto-dotnet dotnet test --no-build --filter --filter FullyQualifiedName~Pulumi.Automation.Tests /p:Version=${DOTNET_VERSION}
$(RUN_TESTSUITE) auto-dotnet dotnet test --no-build --filter FullyQualifiedName~Pulumi.Automation.Tests /p:Version=${DOTNET_VERSION} ${TEST_COVERAGE_ARGS}/dotnet-auto.xml
test_fast:: dotnet_test
$(GO_TEST_FAST) ${PROJECT_PKGS}

View file

@ -7,6 +7,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />