99[ ![ Build] ( https://github.com/dlidstrom/Sprout/actions/workflows/build.yml/badge.svg )] ( https://github.com/dlidstrom/Sprout/actions/workflows/build.yml )
1010[ ![ NuGet version] ( https://badge.fury.io/nu/dlidstrom.Sprout.svg )] ( https://badge.fury.io/nu/dlidstrom.Sprout )
1111
12+ 🔥 Latest news
13+
14+ - Refactoring for improved extensibility.
15+ - Custom runner support has been added.
16+ - Test ordering is now customizable.
17+ - See [ Extending Sprout] ( #-extending-sprout ) for more details.
18+
1219## ✅ Features
1320
14- * Minimalist & expressive BDD-style syntax
15- * Nestable ` describe ` blocks for organizing tests to any depth or complexity
16- * Computation expressions for ` it ` , ` beforeEach ` , ` afterEach `
17- * Asynchronous blocks supported
18- * Pending tests support
19- * Logging for improved traceability
20- * Built-in assertions: ` shouldEqual ` , ` shouldBeTrue ` , ` shouldBeFalse `
21- * These go along way to making your tests readable and expressive due to the
21+ - Minimalist & expressive BDD-style syntax
22+ - Nestable ` describe ` blocks for organizing tests to any depth or complexity
23+ - Computation expressions for ` it ` , ` beforeEach ` , ` afterEach `
24+ - Asynchronous blocks supported
25+ - Pending tests support
26+ - Logging for improved traceability
27+ - Built-in assertions: ` shouldEqual ` , ` shouldBeTrue ` , ` shouldBeFalse `
28+ - These go along way to making your tests readable and expressive due to the
2229 descriptive text that goes along with each ` describe ` block and ` it ` test
2330 case. Note that you may use any exception-based constraints library if
2431 desired ([ FsUnit.Light] ( https://github.com/Lanayx/FsUnit.Light ) works
2532 beautifully).
26- * Support for parameterized tests using normal F# loops within ` describe ` blocks
27- * Pluggable reporters (console, silent, TAP, JSON)
28- * Built for F# — simple and idiomatic
29- * No need for ` <| ` or functions wrapped in parentheses!
30- * No need for complex combination of attributes - it's just all F# code!
33+ - Support for parameterized tests using normal F# loops within ` describe ` blocks
34+ - Pluggable reporters (console, silent, TAP, JSON)
35+ - Built for F# — simple and idiomatic
36+ - No need for ` <| ` or functions wrapped in parentheses!
37+ - No need for complex combination of attributes - it's just all F# code!
3138
3239Sprout provides a clean API for structuring tests. There are a minimum of
3340abstractions. ` describe ` blocks may be nested to any suitable depth. It is all
@@ -47,6 +54,8 @@ dotnet add package dlidstrom.Sprout
4754### 🧪 Example Test
4855
4956``` fsharp
57+ #load "Sprout.fs"
58+
5059open Sprout
5160
5261let suite = describe "A test suite" {
@@ -116,8 +125,11 @@ let suite = describe "A test suite" {
116125 }
117126}
118127
119- // Run the test suite asynchronously
120- runTestSuite
128+ runTestSuiteCustom
129+ // id is used to order the tests (it blocks)
130+ // you can specify a custom ordering function if needed
131+ (DefaultRunner(Reporters.ConsoleReporter("v", "x", "?", " "), id))
132+ suite
121133|> Async.RunSynchronously
122134```
123135
@@ -135,16 +147,16 @@ Output:
135147| ` it ` | Imperative | Any F# expressions, but typically exception-based assertions |
136148| ` beforeEach ` , ` afterEach ` | Imperative | Hook functions that run before and after test cases, respectively |
137149
138- * ** ` describe ` ** - used to define a test suite, or a group of tests. Use the
150+ - ** ` describe ` ** - used to define a test suite, or a group of tests. Use the
139151 descriptive text to create descriptive sentences of expected behaviour.
140- * ** ` it ` ** - used to define test assertions, along with a descriptive text to
152+ - ** ` it ` ** - used to define test assertions, along with a descriptive text to
141153 define the expected behaviour
142- * ** ` beforeEach ` /` afterEach ` ** - hook functions that run before and after test
154+ - ** ` beforeEach ` /` afterEach ` ** - hook functions that run before and after test
143155 cases, respectively
144- * ** ` pending ` ** - used to denote a pending test case
145- * ** ` info ` /` debug ` ** - tracing functions that may be used inside hook functions
156+ - ** ` pending ` ** - used to denote a pending test case
157+ - ** ` info ` /` debug ` ** - tracing functions that may be used inside hook functions
146158 and ` it ` blocks
147- * ** ` Info ` /` Debug ` ** - constructor functions that provide tracing inside
159+ - ** ` Info ` /` Debug ` ** - constructor functions that provide tracing inside
148160 ` describe ` blocks
149161
150162> Tracing works slightly different in ` describe ` blocks due to limitations of me
@@ -158,24 +170,29 @@ You can plug in your own reporter:
158170
159171``` fsharp
160172type MyCustomReporter() =
161- interface ITestReporter with
162- member _.Begin(totalCount) = ...
163- member _.BeginSuite(name, path) = ...
164- member _.ReportResult(result, path) = ...
165- member _.EndSuite(name, path) = ...
166- member _.Info(message, path) = ...
167- member _.Debug(message, path) = ...
168- member _.End(testResults) = ...
173+ inherit TestReporter()
174+ with
175+ override _.Begin(totalCount) = ...
176+ override _.BeginSuite(name, path) = ...
177+ override _.ReportResult(result, path) = ...
178+ override _.EndSuite(name, path) = ...
179+ override _.Info(message, path) = ...
180+ override _.Debug(message, path) = ...
181+ override _.End(testResults) = ...
169182```
170183
171184Use it like this:
172185
173186``` fsharp
174- let reporter = MyCustomReporter() :> ITestReporter
175- let results =
176- runTestSuiteWithContext
187+ let reporter = MyCustomReporter()
188+
189+ let failedCount =
190+ runTestSuiteCustom
191+ // id is used to order the tests (it blocks)
192+ // you can specify a custom ordering function if needed
193+ (DefaultRunner(reporter, id))
177194 suite
178- { TestContext.New with Reporter = reporter }
195+ |> Async.RunSynchronously
179196```
180197
181198Available reporters (available in the ` Sprout.Reporters ` namespace):
@@ -187,6 +204,30 @@ Available reporters (available in the `Sprout.Reporters` namespace):
187204
188205---
189206
207+ It is also possible to modify the default or create your own runner. A simple
208+ example is to modify the default runner to run tests in parallel:
209+
210+ ``` fsharp
211+ let parallelRunner = {
212+ new DefaultRunner(Reporters.TapReporter(), id) with
213+ override _.SequenceAsync args = Async.Parallel args }
214+ runTestSuiteCustom
215+ parallelRunner
216+ suite
217+ |> Async.RunSynchronously
218+ ```
219+
220+ ---
221+
222+ ### 🏗️ Testing Sprout Itself
223+
224+ Sprout is tested using [ Bash Automated Testing System] ( https://github.com/bats-core/bats-core ) .
225+ You can run the tests using the following command:
226+
227+ ``` bash
228+ bats .
229+ ```
230+
190231### 📦 Package Info
191232
192233| | |
0 commit comments