Cope with test fixtures which have non-static members (#22)

This commit is contained in:
Patrick Stevens
2024-06-05 14:01:12 +01:00
committed by GitHub
parent 92d2c9b2a5
commit b3fede4343
3 changed files with 83 additions and 13 deletions

View File

@@ -15,6 +15,7 @@
</None>
<Compile Include="TestAppDomain.fs" />
<Compile Include="TestCaseData.fs" />
<Compile Include="TestNonStatic.fs" />
</ItemGroup>
<ItemGroup>

31
Consumer/TestNonStatic.fs Normal file
View File

@@ -0,0 +1,31 @@
namespace Consumer
open System.Threading
open FsUnitTyped
open NUnit.Framework
[<RequireQualifiedAccess>]
module NonStaticTestHelpers =
let count = ref 0
[<TestFixture>]
type TestNonStatic () =
let count = ref 0
member this.Thing = "i'm a thing"
[<Test>]
member this.Foo () =
Interlocked.Increment NonStaticTestHelpers.count |> ignore<int>
Interlocked.Increment count |> ignore<int>
this.Thing |> shouldEqual "i'm a thing"
[<Test>]
static member AnotherTest () =
Interlocked.Increment NonStaticTestHelpers.count |> ignore<int>
1 |> shouldEqual 1
[<OneTimeTearDown>]
member _.TearDown () =
count.Value |> shouldEqual 1
NonStaticTestHelpers.count.Value |> shouldEqual 2