|
1 | 1 | # Sprout: BDD Testing for F# |
2 | 2 |
|
3 | | - |
| 3 | +<img src="logo.png" height="128" width="128" /> |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +```fsharp |
| 8 | +open Sprout |
| 9 | +
|
| 10 | +let s1 = describe "Suite 1" {} |
| 11 | +let s2 = describe "Suite 2" { |
| 12 | + beforeEach { |
| 13 | + debug "Before each test in Suite 2" |
| 14 | + } |
| 15 | +
|
| 16 | + it "should pass in Suite 2" { |
| 17 | + info "This test passes in Suite 2" |
| 18 | + } |
| 19 | +} |
| 20 | +
|
| 21 | +// run collection of suites |
| 22 | +runTestSuite (describe "Main Suite" { s1; s2 }) |
| 23 | +
|
| 24 | +// larger suite example |
| 25 | +let suite = describe "A larger test suite" { |
| 26 | + beforeEach { |
| 27 | + debug "Before each test" |
| 28 | + } |
| 29 | +
|
| 30 | + afterEach { |
| 31 | + debug "After each test" |
| 32 | + } |
| 33 | +
|
| 34 | + it "should pass" { |
| 35 | + info "This test passes" |
| 36 | + } |
| 37 | +
|
| 38 | + it "should fail" { |
| 39 | + info "This test fails" |
| 40 | + failwith "Intentional failure" |
| 41 | + } |
| 42 | +
|
| 43 | + pending "This is a pending test" |
| 44 | +
|
| 45 | + describe "Nested suite" { |
| 46 | + it "should also pass" { |
| 47 | + info "Nested test passes" |
| 48 | + } |
| 49 | + } |
| 50 | +
|
| 51 | + describe "Arithmetic" { |
| 52 | + describe "Addition" { |
| 53 | + it "should add two numbers correctly" { |
| 54 | + let result = 2 + 2 |
| 55 | + result |> shouldEqual 4 |
| 56 | + } |
| 57 | +
|
| 58 | + it "should handle negative numbers" { |
| 59 | + let result = -1 + -1 |
| 60 | + result |> shouldEqual -2 |
| 61 | + } |
| 62 | + } |
| 63 | +
|
| 64 | + describe "Faulty Addition" { |
| 65 | + it "should fail when adding incorrect numbers" { |
| 66 | + let result = 2 + 2 |
| 67 | + result |> shouldEqual 5 |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | +
|
| 73 | +runTestSuite suite |
| 74 | +``` |
| 75 | + |
| 76 | +Output: |
| 77 | + |
| 78 | +```txt |
| 79 | +Main Suite |
| 80 | + Suite 1 |
| 81 | + Suite 2 |
| 82 | + Before each test in Suite 2 |
| 83 | + This test passes in Suite 2 |
| 84 | + ✅ passed: should pass in Suite 2 |
| 85 | +All tests passed! |
| 86 | +Summary: 1 passed, 0 failed, 0 pending |
| 87 | +A larger test suite |
| 88 | +Before each test |
| 89 | +This test passes |
| 90 | +After each test |
| 91 | + ✅ passed: should pass |
| 92 | +Before each test |
| 93 | +This test fails |
| 94 | +After each test |
| 95 | + ❌ failed: should fail - Intentional failure |
| 96 | +Before each test |
| 97 | +After each test |
| 98 | + ❔ pending: This is a pending test |
| 99 | + Nested suite |
| 100 | + Before each test |
| 101 | + Nested test passes |
| 102 | + After each test |
| 103 | + ✅ passed: should also pass |
| 104 | + Arithmetic |
| 105 | + Addition |
| 106 | + Before each test |
| 107 | + After each test |
| 108 | + ✅ passed: should add two numbers correctly |
| 109 | + Before each test |
| 110 | + After each test |
| 111 | + ✅ passed: should handle negative numbers |
| 112 | + Faulty Addition |
| 113 | + Before each test |
| 114 | + After each test |
| 115 | + ❌ failed: should fail when adding incorrect numbers - Expected 5 but got 4 |
| 116 | +There were 2 test failures: |
| 117 | +- A larger test suite / should fail - Intentional failure |
| 118 | +- A larger test suite / Arithmetic / Faulty Addition / should fail when adding incorrect numbers - Expected 5 but got 4 |
| 119 | +Summary: 4 passed, 2 failed, 1 pending |
| 120 | +``` |
0 commit comments