1
1
# sbt-scoverage
2
2
3
- [ ![ Gitter ] ( https://img.shields.io/ gitter/room/scoverage/scoverage.svg )] ( https:// gitter.im/scoverage/scoverage )
4
- [ ![ Maven Central ] ( https://img.shields.io/github/v/release/scoverage/sbt-scoverage?label= maven-central )] ( https://search. maven.org/artifact/org.scoverage/sbt-scoverage/ )
5
- [ ![ License ] ( http://img.shields.io/: license-Apache%202-red.svg )] ( http://www.apache.org/licenses/LICENSE-2.0.txt )
3
+ [ ![ gitter-badge ] [ ]] [ gitter ]
4
+ [ ![ maven-badge ] [ ]] [ maven ]
5
+ [ ![ license-badge ] [ ]] [ license ]
6
6
7
- sbt-scoverage is an sbt plugin that offers support for Scala code coverage using
8
- [ scoverage] ( https://github.com/scoverage/scalac-scoverage-plugin ) . This plugin
9
- supports Scala 2.12, 2.13, and 3.
7
+ sbt-scoverage is an sbt plugin that offers support for Scala code
8
+ coverage using [ scoverage] [ ] . This plugin supports Scala 2.12, 2.13,
9
+ and 3.
10
10
11
- ** NOTE** : that ScalaJS and Scala Native support is limited to Scala 2.
12
- ** NOTE** : that Scala 3 support starts with 3.2.x.
11
+ ** NOTE** : ScalaJS and Scala Native support is limited to Scala 2.
12
+
13
+ ** NOTE** : Scala 3 support starts with 3.2.x.
13
14
14
15
## Setup
15
16
16
- ** Requirements** : Requires sbt 1.2.8 or above
17
+ ** Requirements** : Requires sbt 1.2.8 or above.
17
18
18
19
In ` project/plugins.sbt ` :
19
20
``` scala
@@ -46,50 +47,54 @@ To generate the coverage reports run
46
47
sbt coverageReport
47
48
```
48
49
49
- Coverage reports will be in your ` target/scala-<scala-version>/scoverage-report `
50
- directory. There are HTML and XML reports. The XML is useful if you need to
51
- programatically use the results, or if you're writing a tool.
50
+ Coverage reports will be in your
51
+ ` target/scala-<scala-version>/scoverage-report ` directory. There are
52
+ HTML and XML reports. The XML is useful if you need to programatically
53
+ use the results, or if you're writing a tool.
52
54
53
- ** NOTE** : If you're running the coverage reports from within an sbt console
54
- session (as opposed to one command per sbt launch), then the ` coverage ` command
55
- is sticky. To turn it back off when you're done running reports, use the
56
- ` coverageOff ` command or reset ` coverageEnabled ` with `set coverageEnabled :=
57
- false`.
55
+ ** NOTE** : If you're running the coverage reports from within an sbt
56
+ console session (as opposed to one command per sbt launch), then the
57
+ ` coverage ` command is sticky. To turn it back off when you're done
58
+ running reports, use the ` coverageOff ` command or reset
59
+ ` coverageEnabled ` with ` set coverageEnabled := false` .
58
60
59
61
### Multi project reports
60
62
61
- By default, scoverage will generate reports for each project separately. You can
62
- merge them into an aggregated report by using the following:
63
+ By default, scoverage will generate reports for each project
64
+ separately. You can merge them into an aggregated report by using the
65
+ following:
63
66
64
67
```
65
68
$ sbt coverageAggregate
66
69
```
67
70
68
- ** NOTE** : You do not need to run ` coverageReport ` before ` coverageAggregate ` ; it
69
- aggregates over the sub-projects' coverage data directly, not the report xml.
71
+ ** NOTE** : You do not need to run ` coverageReport ` before
72
+ ` coverageAggregate ` ; it aggregates over the sub-projects' coverage
73
+ data directly, not the report xml.
70
74
71
75
### Exclude classes and packages and files
72
76
73
- You can exclude classes from being considered for coverage measurement by
74
- providing semicolon-separated list of regular expressions.
77
+ You can exclude classes from being considered for coverage measurement
78
+ by providing semicolon-separated list of regular expressions.
75
79
76
80
``` scala
77
81
coverageExcludedPackages := " <empty>;Reverse.*;.*AuthService.*;models\\ .data\\ ..*"
78
82
```
79
83
80
- The regular expressions are matched against the fully qualified class name, and
81
- must match the entire string to take effect. Any matched classes will not be
82
- instrumented or included in the coverage report.
84
+ The regular expressions are matched against the fully qualified class
85
+ name, and must match the entire string to take effect. Any matched
86
+ classes will not be instrumented or included in the coverage report.
83
87
84
88
You can also exclude files and file paths.
85
89
86
90
``` scala
87
91
coverageExcludedFiles := " .*\\ /two\\ /GoodCoverage;.*\\ /three\\ /.*"
88
92
```
89
93
90
- Note: The ` .scala ` file extension needs to be omitted from the filename, if one is given.
94
+ ** NOTE** : The ` .scala ` file extension needs to be omitted from the
95
+ filename, if one is given.
91
96
92
- Note : These two options only work for Scala2 and Scala 3.4.2+.
97
+ ** NOTE ** : These two options only work for Scala2 and Scala 3.4.2+.
93
98
94
99
You can also mark sections of code with comments like:
95
100
@@ -102,7 +107,7 @@ You can also mark sections of code with comments like:
102
107
Any code between two such comments will not be instrumented or included in the
103
108
coverage report.
104
109
105
- Note : Comments exclusion works only for Scala2.
110
+ ** NOTE ** : Comments exclusion works only for Scala2.
106
111
107
112
### Minimum coverage
108
113
@@ -118,13 +123,14 @@ coverageMinimumStmtPerFile := 85
118
123
coverageMinimumBranchPerFile := 80
119
124
```
120
125
121
- These settings will be enforced when the reports are generated. If you generate
122
- an aggregate report using ` coverageAggregate ` then these settings will apply to
123
- that report.
126
+ These settings will be enforced when the reports are generated. If
127
+ you generate an aggregate report using ` coverageAggregate ` then these
128
+ settings will apply to that report.
124
129
125
130
### Override Location for Coverage Data And Report
126
131
127
- If desired, one could override the default location for generating the sbt report and data through setting ` coverageDataDir ` :
132
+ If desired, one could override the default location for generating the
133
+ sbt report and data through setting ` coverageDataDir ` :
128
134
129
135
Example in data-dir test:
130
136
``` scala
@@ -138,49 +144,68 @@ set coverageDataDir := file("/tmp")
138
144
139
145
## Trouble-shooting failing tests
140
146
141
- scoverage does a lot of file writing behind the scenes in order to track which
142
- statements have been executed. If you are running into a scenario where your
143
- tests normally pass, but fail when scoverage is enabled, then the culprit can be
144
- one of the following:
147
+ scoverage does a lot of file writing behind the scenes in order to
148
+ track which statements have been executed. If you are running into a
149
+ scenario where your tests normally pass, but fail when scoverage is
150
+ enabled, then the culprit can be one of the following:
145
151
146
- * timing issues on futures and other async operations, try upping the timeouts by an order of magnitude.
147
- * tests are run in a sandbox mode (such as with ` java.security.PrivilegedAction<T> ` ), try running the tests outside of the sandbox.
152
+ * timing issues on futures and other async operations, try upping the
153
+ timeouts by an order of magnitude.
154
+ * tests are run in a sandbox mode (such as with
155
+ ` java.security.PrivilegedAction<T> ` ), try running the tests outside
156
+ of the sandbox.
148
157
149
158
## Example project
150
159
151
- [ the scoverage samples project] ( https://github.com/scoverage/sbt-scoverage-samples ) .
160
+ To see the plugin in action you can checkout the scoverage [ samples] [ ]
161
+ project.
152
162
153
163
## Integrations
154
164
155
165
### Codacy
156
166
157
- [ Codacy] ( https://www.codacy.com ) integrates with your favorite coverage tool to
158
- provide an in-depth overlook of your project status. scoverage information can
159
- be integrated into Codacy through the
160
- [ codacy-coverage-reporter] ( https://github.com/codacy/codacy-coverage-reporter ) .
167
+ [ Codacy] [ ] integrates with your favorite coverage tool to provide an
168
+ in-depth overlook of your project status. scoverage information can be
169
+ integrated into Codacy through the [ codacy-coverage-reporter] [ ] .
161
170
162
171
### Coveralls
163
172
164
- If you have an open source project then you can add code coverage metrics with
165
- the [ Coveralls] ( https://coveralls.io/ ) . scoverage will integrate with coveralls
166
- using the [ sbt-coveralls] ( https://github.com/scoverage/sbt-coveralls ) plugin.
173
+ If you have an open source project then you can publish the code
174
+ coverage metrics with [ Coveralls] [ ] . This plugin will integrate with
175
+ coveralls using the [ sbt-coveralls] [ ] plugin.
167
176
168
177
### Codecov
169
178
170
- You can integrate with [ Codecov] ( https://about.codecov.io/ ) easily sending your
171
- reports there via your CI. You can see an example of this here in
172
- [ codecov/example-scala] ( https://github.com/codecov/example-scala ) .
179
+ You can also integrate with [ Codecov] [ ] by sending your reports there
180
+ via your CI. You can see an example in [ codecov-example-scala] [ ] .
173
181
174
- ### Plugin for SonarQube
182
+ ### SonarQube
175
183
176
- If you want to visually browse statement coverage reports then use this [ plugin
177
- for SonarQube] ( https://github.com/RadoBuransky/sonar-scoverage- plugin) . It
178
- allows you to review overall project statement coverage as well as dig deeper
179
- into sub-modules, directories and source code files to see uncovered statements.
180
- Statement coverage measurement can become an integral part of your team's
181
- continuous integration process and a required quality standard.
184
+ If you want to visually browse coverage reports then you can use the
185
+ [ SonarQube] [ ] plugin. It allows you to review overall project
186
+ statement coverage as well as dig deeper into sub-modules, directories
187
+ and source code files to see uncovered statements. Statement coverage
188
+ measurement can become an integral part of your team's continuous
189
+ integration process and a required quality standard.
182
190
183
191
## Release Notes
184
192
185
- For any information on releases and upgrading, please refer to the [ release
186
- page] ( https://github.com/scoverage/sbt-scoverage/releases ) .
193
+ For any information on releases and upgrading, please refer to the
194
+ [ release] [ ] page.
195
+
196
+ [ gitter ] : https://gitter.im/scoverage/scoverage
197
+ [ gitter-badge ] : https://img.shields.io/gitter/room/scoverage/scoverage.svg
198
+ [ maven ] : https://search.maven.org/artifact/org.scoverage/sbt-scoverage
199
+ [ maven-badge ] : https://index.scala-lang.org/scoverage/sbt-scoverage/sbt-scoverage/latest.svg&label=maven-central
200
+ [ license ] : http://www.apache.org/licenses/LICENSE-2.0.txt
201
+ [ license-badge ] : http://img.shields.io/:license-Apache%202-red.svg
202
+ [ scoverage ] : https://github.com/scoverage/scalac-scoverage-plugin
203
+ [ samples ] : https://github.com/scoverage/sbt-scoverage-samples
204
+ [ codacy-coverage-reporter ] : https://github.com/codacy/codacy-coverage-reporter
205
+ [ Codacy ] : https://www.codacy.com
206
+ [ Coveralls ] : https://coveralls.io
207
+ [ sbt-coveralls ] : https://github.com/scoverage/sbt-coveralls
208
+ [ Codecov ] : https://about.codecov.io
209
+ [ codecov-example-scala ] : https://github.com/codecov/example-scala
210
+ [ SonarQube ] : https://github.com/RadoBuransky/sonar-scoverage-plugin
211
+ [ release ] : https://github.com/scoverage/sbt-scoverage/releases
0 commit comments