You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-3Lines changed: 9 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,19 +74,25 @@ Coverlet allows you to specify a coverage threshold below which it fails the bui
74
74
dotnet test /p:CollectCoverage=true /p:Threshold=80
75
75
```
76
76
77
-
The above command will automatically fail the build if the average code coverage of all instrumented modules falls below 80%.
77
+
The above command will automatically fail the build if the line, branch or method coverage of _any_ of the instrumented modules falls below 80%. You can specify what type of coverage to apply the threshold value to using the `ThresholdType` property. For example to apply the threshold check to only **line** coverage:
78
+
79
+
```bash
80
+
dotnet test /p:CollectCoverage=true /p:Threshold=80 /p:ThresholdType=line
81
+
```
82
+
83
+
You can specify multiple values for `ThresholdType` by separating them with commas. Valid values include `line`, `branch` and `method`.
78
84
79
85
### Excluding From Coverage
80
86
81
-
#### Attributes
87
+
#### Attributes
82
88
You can ignore a method or an entire class from code coverage by creating and applying any of the following attributes:
83
89
84
90
* ExcludeFromCoverage
85
91
* ExcludeFromCoverageAttribute
86
92
87
93
Coverlet just uses the type name, so the attributes can be created under any namespace of your choosing.
88
94
89
-
#### Source Files
95
+
#### Source Files
90
96
You can also ignore specific source files from code coverage using the `ExcludeByFile` property
91
97
- Use single or multiple paths (separate by comma)
92
98
- Use absolute or relative paths (relative to the project directory)
exceptionBuilder.AppendLine($"'{Path.GetFileNameWithoutExtension(module.Key)}' has a line coverage '{linePercent}%' below specified threshold '{_threshold}%'");
107
93
thresholdFailed=true;
108
-
exceptionBuilder.AppendLine($"Overall average '{thresholdType}' coverage '{lineAverage}%' is lower than specified threshold '{_threshold}%'");
exceptionBuilder.AppendLine($"'{Path.GetFileNameWithoutExtension(module.Key)}' has a branch coverage '{branchPercent}%' below specified threshold '{_threshold}%'");
113
99
thresholdFailed=true;
114
-
exceptionBuilder.AppendLine($"Overall average '{thresholdType}' coverage '{branchAverage}%' is lower than specified threshold '{_threshold}%'");
exceptionBuilder.AppendLine($"'{Path.GetFileNameWithoutExtension(module.Key)}' has a method coverage '{methodPercent}%' below specified threshold '{_threshold}%'");
119
105
thresholdFailed=true;
120
-
exceptionBuilder.AppendLine($"Overall average '{thresholdType}' coverage '{methodAverage}%' is lower than specified threshold '{_threshold}%'");
0 commit comments