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
A SBT plugin to use [ScalaTest](http://www.scalatest.org/) with scripted-plugin to test your SBT plugins
15
15
16
-
Traditionally, to test a SBT plugin, you had to create subprojects in `/sbt-test`, then in the subprojects, create SBT tasks to perform the testing, then specify the tasks to execute in a `test` file (see http://www.scala-sbt.org/0.13/docs/Testing-sbt-plugins.html).
16
+
Traditionally, to test a SBT plugin, you had to create subprojects in `/sbt-test`, then in the subprojects, create SBT tasks to perform the testing, then specify the tasks to execute in a `test` file (see <http://www.scala-sbt.org/0.13/docs/Testing-sbt-plugins.html>).
17
17
18
-
This is fine when performing simple tests, but for complicated tests (see http://www.scala-sbt.org/0.13/docs/Testing-sbt-plugins.html#step+6%3A+custom+assertion), this can get messy really quickly:
19
-
- It sucks to not be able to write tests in a BDD style (except by using comments, which feels clunky).
20
-
- Manually writing code to print the test results to the console for each subproject is a pain.
18
+
This is fine when performing simple tests, but for complicated tests (see <http://www.scala-sbt.org/0.13/docs/Testing-sbt-plugins.html#step+6%3A+custom+assertion>), this can get messy really quickly:
19
+
20
+
- It sucks to not be able to write tests in a BDD style (except by using comments, which feels clunky).
21
+
- Manually writing code to print the test results to the console for each subproject is a pain.
21
22
22
23
This plugin leverages ScalaTest's powerful assertion system (to automatically print useful messages on assertion failure) and its expressive DSLs.
23
24
24
25
This plugin allows you to use any of ScalaTest's test [Suites](http://www.scalatest.org/user_guide/selecting_a_style), including [AsyncTestSuites](http://www.scalatest.org/user_guide/async_testing).
25
26
26
27
## Notes
27
-
- Do not use ScalaTest's [ParallelTestExecution](http://doc.scalatest.org/3.0.0/index.html#org.scalatest.ParallelTestExecution) mixin with this plugin. `ScriptedScalaTestSuiteMixin` runs `sbt clean` before each test, which may cause weird side effects when run in parallel.
28
-
- When executing SBT tasks in tests, use `Project.runTask(<task>, state.value)` instead of `<task>.value`. Calling `<task>.value` declares it as a dependency, which executes before the tests, not when the line is called.
29
-
- When implementing [BeforeAndAfterEach](http://doc.scalatest.org/3.0.0/index.html#org.scalatest.BeforeAndAfterEach)'s `beforeEach`, make sure to invoke `super.beforeEach` afterwards:
28
+
29
+
- Do not use ScalaTest's [ParallelTestExecution](http://doc.scalatest.org/3.0.0/index.html#org.scalatest.ParallelTestExecution) mixin with this plugin. `ScriptedScalaTestSuiteMixin` runs `sbt clean` before each test, which may cause weird side effects when run in parallel.
30
+
- When executing SBT tasks in tests, use `Project.runTask(<task>, state.value)` instead of `<task>.value`. Calling `<task>.value` declares it as a dependency, which executes before the tests, not when the line is called.
31
+
- When implementing [BeforeAndAfterEach](http://doc.scalatest.org/3.0.0/index.html#org.scalatest.BeforeAndAfterEach)'s `beforeEach`, make sure to invoke `super.beforeEach` afterwards:
32
+
30
33
```scala
31
34
overrideprotecteddefbeforeEach():Unit= {
32
35
// ...
33
36
super.beforeEach() // To be stackable, must call super.beforeEach
34
37
}
35
38
```
36
-
- This SBT plugin is now tested using itself!
39
+
40
+
- This SBT plugin is now tested using itself!
37
41
38
42
## Usage
39
43
40
44
### Step 1: Include the scripted-plugin in your build
41
45
42
46
Add the following to your main project's `project/scripted.sbt` (create file it if doesn't exist):
If you are using [sbt-cross-building](https://github.com/jrudolph/sbt-cross-building) (SBT < 0.13.6), don't add scripted-plugin to `project/scripted.sbt`, and replace `ScriptedPlugin.scriptedSettings` in `build.sbt` with `CrossBuilding.scriptedSettings`.
81
+
If you are using [sbt-cross-building](https://github.com/jrudolph/sbt-cross-building) (SBT < 0.13.6), don't add scripted-plugin to `project/scripted.sbt`, and replace `ScriptedPlugin.scriptedSettings` in `build.sbt` with `CrossBuilding.scriptedSettings`.
77
82
78
83
#### SBT 1.0.x-1.1.x
79
84
@@ -89,7 +94,7 @@ lazy val root = (project in file("."))
Put __only__ the following in the `sbt-test/<test-group>/<test-name>/test` script file:
137
+
Put **only** the following in the `sbt-test/<test-group>/<test-name>/test` script file:
131
138
132
139
`> scriptedScalatest`
133
140
134
141
### Step 6: Configure project settings for the plugin
135
142
136
143
In `sbt-test/<test-group>/<test-name>/build.sbt`, create a new ScalaTest Suite/Spec, mixin `ScriptedScalaTestSuiteMixin` and pass it into `scriptedScalaTestSpec`. When mixing in `ScriptedScalaTestSuiteMixin`, implement `sbtState` as `state.value`.
137
144
138
-
Using SBT's Example in http://www.scala-sbt.org/0.13/docs/Testing-sbt-plugins.html#step+6%3A+custom+assertion:
145
+
Using SBT's Example in <http://www.scala-sbt.org/0.13/docs/Testing-sbt-plugins.html#step+6%3A+custom+assertion>:
| scriptedScalaTestSpec | Option[Suite with ScriptedScalaTestSuiteMixin]|__Required__. The ScalaTest Suite/Spec. If not configured (defaults to `None`), no tests will be executed. |
180
-
| scriptedScalaTestDurations | Boolean |__Optional__. If `true`, displays durations of tests. Defaults to `true`. |
181
-
| scriptedScalaTestStacks | NoStacks / ShortStacks / FullStacks |__Optional__. The length of stack traces to display for failed tests. `NoStacks` will not display any stack traces. `ShortStacks` displays short stack traces. `FullStacks` displays full stack traces. Defaults to `NoStacks`. |
182
-
| scriptedScalaTestStats | Boolean |__Optional__. If `true`, displays various statistics of tests. Defaults to `true`. |
187
+
| scriptedScalaTestSpec | Option[Suite with ScriptedScalaTestSuiteMixin]|**Required**. The ScalaTest Suite/Spec. If not configured (defaults to `None`), no tests will be executed. |
188
+
| scriptedScalaTestDurations | Boolean |**Optional**. If `true`, displays durations of tests. Defaults to `true`. |
189
+
| scriptedScalaTestStacks | NoStacks / ShortStacks / FullStacks |**Optional**. The length of stack traces to display for failed tests. `NoStacks` will not display any stack traces. `ShortStacks` displays short stack traces. `FullStacks` displays full stack traces. Defaults to `NoStacks`. |
190
+
| scriptedScalaTestStats | Boolean |**Optional**. If `true`, displays various statistics of tests. Defaults to `true`. |
| scriptedScalatest | Executes all test configured in `scriptedScalaTestSpec`. This task must be [configured for scripted-plugin to run in the `test` script file](#step-5-configure-test-script). |
189
197
190
198
## Licence
@@ -193,6 +201,6 @@ Copyright 2017, 2018, 2019 Daniel Shuy
193
201
194
202
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
195
203
196
-
http://www.apache.org/licenses/LICENSE-2.0
204
+
<http://www.apache.org/licenses/LICENSE-2.0>
197
205
198
206
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
0 commit comments