@@ -51,31 +51,36 @@ open Sprout
5151
5252let suite = describe "A test suite" {
5353 Info "Top level info message"
54+
55+ // variables may be used to store state across tests
56+ let mutable b = false
57+ beforeEach { b <- true }
5458 it "should pass" {
5559 info "This test passes"
60+
61+ // simple assertions included out-of-the-box
62+ b |> shouldBeTrue
5663 }
5764
5865 it "should fail" {
5966 info "This test fails"
6067 failwith "Intentional failure"
6168 }
6269
70+ // use pending to mark tests that are not yet implemented
6371 pending "This is a pending test"
6472
65- describe "Nested suite" {
66- Debug "Use beforeEach and afterEach for setup and teardown"
67- beforeEach {
68- debug "Before each test"
69- }
73+ describe "Async works too" {
74+ Debug "Async test example"
7075
71- afterEach {
72- debug "After each test"
73- }
74- it "should also pass" {
75- info "Nested test passes"
76+ // asynchronous flows are supported
77+ it "should run asynchronously" {
78+ do! Async.Sleep 1000
79+ info "Async test completed"
7680 }
7781 }
7882
83+ // use nested suites to organize tests
7984 describe "Arithmetic" {
8085 describe "Addition" {
8186 it "should add two numbers correctly" {
@@ -90,24 +95,30 @@ let suite = describe "A test suite" {
9095 result |> shouldEqual 9
9196 }
9297 }
93- }
9498
95- describe "Comparisons" {
96- debug "Testing comparisons"
97- it "should compare numbers correctly" {
98- 5 > 3 |> shouldBeTrue
99+ describe "Comparisons" {
100+ debug "Testing comparisons"
101+ it "should compare numbers correctly" {
102+ 5 > 3 |> shouldBeTrue
103+ }
99104 }
100- }
101105
102- describe "Parameterized Tests" {
103- info "Simply embed test cases and loop over them"
104- let numbers = [1; 2; 3; 4; 5]
105- for n in numbers do
106- it $"should handle number {n}" {
107- n > 0 |> shouldBeTrue
108- }
106+ // parameterized tests are supported using regular F# loops
107+ // type-safe as expected without any special syntax
108+ describe "Parameterized Tests" {
109+ info "Simply embed test cases and loop over them"
110+ let numbers = [1; 2; 3; 4; 5]
111+ for n in numbers do
112+ it $"should handle number {n}" {
113+ n > 0 |> shouldBeTrue
114+ }
115+ }
109116 }
110117}
118+
119+ // Run the test suite asynchronously
120+ runTestSuite
121+ |> Async.RunSynchronously
111122```
112123
113124Output:
0 commit comments