FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cloud-admin/scripts/dotnet/Get-CodeCoverage.ps1 at main · goodtocode/cloud-admin · GitHub
goodtocode
/
cloud-admin
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cloud-admin
/
scripts
/
dotnet
/
Get-CodeCoverage.ps1
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (54 loc) · 3.11 KB
Breadcrumbs
cloud-admin
/
scripts
/
dotnet
/
Get-CodeCoverage.ps1
Copy path
File metadata and controls
65 lines (54 loc) · 3.11 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#
###################################################################################
#
To execute
#
1. In powershell, set security polilcy for this script:
#
Set-ExecutionPolicy Unrestricted -Scope Process -Force
#
2. Change directory to the script folder:
#
CD src (wherever your script is)
#
3. In powershell, run script:
#
.\Get-CodeCoverage.ps1 -TestProjectFilter 'MyTests.*.csproj' -ProdPackagesOnly -ProductionAssemblies 'MyApp.Core','MyApp.Web'
#
This script is for local use to analyze code coverage in more detail using HTML report.
#
###################################################################################
Param
(
[
string
]
$TestProjectFilter
=
'
*Tests*.csproj
'
,
[
switch
]
$ProdPackagesOnly
=
$false
,
[
string
[]]
$ProductionAssemblies
=
@
()
)
#
###################################################################################
if
(
$IsWindows
) {
Set-ExecutionPolicy
Unrestricted
-
Scope
Process
-
Force}
$VerbosePreference
=
'
SilentlyContinue
'
#
'Continue'
#
###################################################################################
&
dotnet tool install
-
g coverlet.console
&
dotnet tool install
-
g dotnet
-
reportgenerator
-
globaltool
$timestamp
=
Get-Date
-
Format
"
yyyyMMdd-HHmmss
"
$scriptPath
=
Get-Item
-
Path
$PSScriptRoot
$coverageOutputPath
=
Join-Path
$scriptPath
"
TestResults\Coverage\
$timestamp
"
$reportOutputPath
=
Join-Path
$scriptPath
"
TestResults\Reports\
$timestamp
"
New-Item
-
ItemType Directory
-
Force
-
Path
$coverageOutputPath
New-Item
-
ItemType Directory
-
Force
-
Path
$reportOutputPath
$testProjects
=
Get-ChildItem
$scriptPath
-
Filter
$TestProjectFilter
-
Recurse
Write-Host
"
Found
$
(
$testProjects
.Count
)
test projects in
$scriptPath
that match
$TestProjectFilter
.
"
if
(
$testProjects
.Count
-eq
0
)
{
stop
}
foreach
(
$project
in
$testProjects
) {
$testProjectPath
=
$project
.FullName
Write-Host
"
Running tests for project:
$
(
$testProjectPath
)
"
$frameworkDir
=
Get-ChildItem
-
Path (
Join-Path
$project
.Directory.FullName
"
bin\Debug
"
)
-
Directory
|
Where-Object
{
$_
.Name
-like
"
net*
"
}
|
Sort-Object
Name
-
Descending
|
Select-Object
-
First
1
$buildOutput
=
Join-Path
-
Path
$frameworkDir
.FullName
-
ChildPath
"
$
(
$project
.BaseName
)
.dll
"
$coverageFile
=
Join-Path
$coverageOutputPath
"
coverage.cobertura.xml
"
Write-Host
"
Analyzing code coverage for:
$buildOutput
"
coverlet
$buildOutput
--
target
"
dotnet
"
--
targetargs
"
test
$
(
$project
.FullName
)
--no-build
"
--
format cobertura
--
output
$coverageFile
}
#
Generate HTML report
if
(
$ProdPackagesOnly
) {
$assemblyFilters
=
(
$ProductionAssemblies
|
ForEach-Object
{
"
+
$_
"
})
-join
"
;
"
$assemblyFilters
=
(
$ProductionAssemblies
|
ForEach-Object
{
"
+
$_
"
})
-join
"
;
"
&
reportgenerator
-
reports:
"
$coverageOutputPath
/**/coverage.cobertura.xml
"
-
targetdir:
$reportOutputPath
-
reporttypes:Html
-
assemblyfilters:
$assemblyFilters
}
else
{
&
reportgenerator
-
reports:
"
$coverageOutputPath
/**/coverage.cobertura.xml
"
-
targetdir:
$reportOutputPath
-
reporttypes:Html
}
Write-Host
"
Code coverage report generated at:
$reportOutputPath
"
$reportIndexHtml
=
Join-Path
$reportOutputPath
"
index.html
"
Invoke-Item
-
Path
$reportIndexHtml
Back
|
FazBrowse Home
|
New Git URL