-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.fsx
More file actions
100 lines (85 loc) · 2.31 KB
/
sample.fsx
File metadata and controls
100 lines (85 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#load "Sprout.fs"
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 "Async works too" {
Debug "Async test example"
// 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" {
let result = 2 + 2
result |> shouldEqual 4
}
}
describe "Multiplication" {
it "should multiply two numbers correctly" {
let result = 3 * 3
result |> shouldEqual 9
}
}
describe "Comparisons" {
debug "Testing comparisons"
it "should compare numbers correctly" {
5 > 3 |> 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
}
}
}
}
let run() =
(*
// simple way to run the tests and get the number of failed tests:
describe "System Specs" {
suite // list your suites here
}
|> runTestSuite
|> Async.RunSynchronously
|> Array.filter _.Outcome.IsFailed
|> Array.length
*)
// more control over the test run using a custom reporter
suite
|> runTestSuiteCustom
// id is used to order the tests (it blocks)
// you can specify a custom ordering function if needed
(DefaultRunner(Reporters.ConsoleReporter("v", "x", "?", " "), id))
|> Async.RunSynchronously
|> Array.filter _.Outcome.IsFailed
|> Array.length
#if !INTERACTIVE
// run tests as a console application
[<EntryPoint>]
let main _ = run()
#else
do run() |> ignore
#endif