mirror of
https://github.com/Smaug123/unofficial-nunit-runner
synced 2025-10-07 18:18:39 +00:00
Self-hosting tests (#11)
This commit is contained in:
61
Consumer/TestSetUp.fs
Normal file
61
Consumer/TestSetUp.fs
Normal file
@@ -0,0 +1,61 @@
|
||||
namespace Consumer
|
||||
|
||||
open FsUnitTyped
|
||||
open System.Threading
|
||||
open NUnit.Framework
|
||||
|
||||
[<TestFixture>]
|
||||
module TestSetUp =
|
||||
|
||||
let haveOneTimeSetUp = ref 0
|
||||
|
||||
[<OneTimeSetUp>]
|
||||
let oneTimeSetUp () =
|
||||
if Interlocked.Increment haveOneTimeSetUp <> 1 then
|
||||
failwith "one time setup happened more than once"
|
||||
|
||||
let setUpTimes = ref 0
|
||||
let tearDownTimes = ref 0
|
||||
|
||||
let setUpTimesSeen = ResizeArray<int> ()
|
||||
let tearDownTimesSeen = ResizeArray<int> ()
|
||||
|
||||
[<SetUp>]
|
||||
let setUp () =
|
||||
haveOneTimeSetUp.Value |> shouldEqual 1
|
||||
Interlocked.Increment setUpTimes |> setUpTimesSeen.Add
|
||||
|
||||
[<TearDown>]
|
||||
let tearDown () =
|
||||
Interlocked.Increment tearDownTimes |> tearDownTimesSeen.Add
|
||||
|
||||
let haveOneTimeTearDown = ref 0
|
||||
|
||||
[<OneTimeTearDown>]
|
||||
let oneTimeTearDown () =
|
||||
if Interlocked.Increment haveOneTimeTearDown <> 1 then
|
||||
failwith "one time tear down happened more than once"
|
||||
|
||||
setUpTimesSeen
|
||||
|> Seq.toList
|
||||
// Six tests: one for Test, two for the TestCase, three for the Repeat.
|
||||
|> shouldEqual [ 1..6 ]
|
||||
|
||||
tearDownTimesSeen |> Seq.toList |> shouldEqual [ 1..6 ]
|
||||
|
||||
[<Test>]
|
||||
let ``Test 1`` () =
|
||||
haveOneTimeTearDown.Value |> shouldEqual 0
|
||||
1 |> shouldEqual 1
|
||||
|
||||
[<TestCase "h">]
|
||||
[<TestCase "i">]
|
||||
let ``Test 2`` (s : string) =
|
||||
haveOneTimeTearDown.Value |> shouldEqual 0
|
||||
s.Length |> shouldEqual 1
|
||||
|
||||
[<Test>]
|
||||
[<Repeat 3>]
|
||||
let ``Test 3`` () =
|
||||
haveOneTimeTearDown.Value |> shouldEqual 0
|
||||
1 |> shouldEqual 1
|
Reference in New Issue
Block a user