-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📈 Use a common code coverage build script
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/sh -eu | ||
|
||
# function to display commands | ||
exe() { echo; echo "\$ $*" ; "$@" ; } | ||
|
||
# Parameters | ||
framework="${1-netcoreapp2.1}" | ||
config="${2-Debug}" | ||
|
||
testResults="test/TestResults" | ||
include="[Tesla.NET]*" | ||
exclude="[*.Tests]*" | ||
|
||
# Cannot use a bash solution in alpine builds https://stackoverflow.com/a/246128 | ||
#rootDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
rootDir=$(pwd) | ||
|
||
testProj1="$rootDir/test/Tesla.NET.Tests/Tesla.NET.Tests.csproj" | ||
|
||
# Restore the packages | ||
exe dotnet restore "$rootDir" | ||
|
||
# Build the test projects | ||
exe dotnet build --no-restore -f "$framework" -c "$config" "$testProj1" | ||
|
||
# Execute the tests | ||
exe dotnet test --no-restore --no-build -f "$framework" -c "$config" \ | ||
"$testProj1" \ | ||
--results-directory "$rootDir/$testResults/output/" \ | ||
--logger "\"trx;LogFileName=$(basename "$testProj1" .csproj).trx\"" \ | ||
/p:CollectCoverage=true \ | ||
/p:Include="$include" \ | ||
/p:Exclude="$exclude" \ | ||
/p:CoverletOutput="$rootDir/$testResults/" \ | ||
/p:CoverletOutputFormat="\"json,opencover\"" | ||
|
||
# Install trx2junit if not already installed | ||
if [ ! -f "$rootDir/$testResults/tools/trx2junit" ] | ||
then | ||
exe dotnet tool install trx2junit --tool-path "$rootDir/$testResults/tools" | ||
fi | ||
|
||
# Install ReportGenerator if not already installed | ||
if [ ! -f "$rootDir/$testResults/tools/reportgenerator" ] | ||
then | ||
exe dotnet tool install dotnet-reportgenerator-globaltool --tool-path "$rootDir/$testResults/tools" | ||
fi | ||
|
||
# Convert the MSTest trx files to junit xml | ||
exe "$rootDir/$testResults/tools/trx2junit" "$rootDir/$testResults/output"/*.trx | ||
|
||
# Generate the reports | ||
exe "$rootDir/$testResults/tools/reportgenerator" \ | ||
"-verbosity:Info" \ | ||
"-reports:$rootDir/$testResults/coverage.opencover.xml" \ | ||
"-targetdir:$rootDir/$testResults/Report" \ | ||
"-reporttypes:Html" |