Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 34 additions & 23 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,36 @@ open Sprout

let suite = describe "A test suite" {
Info "Top level info message"

// variables may be used to store state across tests
let mutable b = false
beforeEach { b <- true }
it "should pass" {
info "This test passes"

// simple assertions included out-of-the-box
b |> shouldBeTrue
}

it "should fail" {
info "This test fails"
failwith "Intentional failure"
}

// use pending to mark tests that are not yet implemented
pending "This is a pending test"

describe "Nested suite" {
Debug "Use beforeEach and afterEach for setup and teardown"
beforeEach {
debug "Before each test"
}
describe "Async works too" {
Debug "Async test example"

afterEach {
debug "After each test"
}
it "should also pass" {
info "Nested test passes"
// asynchronous flows are supported
it "should run asynchronously" {
do! Async.Sleep 1000
info "Async test completed"
}
}

// use nested suites to organize tests
describe "Arithmetic" {
describe "Addition" {
it "should add two numbers correctly" {
Expand All @@ -90,24 +95,30 @@ let suite = describe "A test suite" {
result |> shouldEqual 9
}
}
}

describe "Comparisons" {
debug "Testing comparisons"
it "should compare numbers correctly" {
5 > 3 |> shouldBeTrue
describe "Comparisons" {
debug "Testing comparisons"
it "should compare numbers correctly" {
5 > 3 |> shouldBeTrue
}
}
}

describe "Parameterized Tests" {
info "Simply embed test cases and loop over them"
let numbers = [1; 2; 3; 4; 5]
for n in numbers do
it $"should handle number {n}" {
n > 0 |> shouldBeTrue
}
// parameterized tests are supported using regular F# loops
// type-safe as expected without any special syntax
describe "Parameterized Tests" {
info "Simply embed test cases and loop over them"
let numbers = [1; 2; 3; 4; 5]
for n in numbers do
it $"should handle number {n}" {
n > 0 |> shouldBeTrue
}
}
}
}

// Run the test suite asynchronously
runTestSuite
|> Async.RunSynchronously
```

Output:
Expand Down
Loading
Loading