First, let me present the test setup in F# (using FsUnit on top of NUnit):
type SimpleRecord = { A: int; B: int }
override x.ToString() = x.A.ToString()
[<TestFixture>]
type ``Simple Test Cases``() =
static member SimpleDataSource =
[|
[|{ A = 1; B = 2} ,3|]
|]
[<TestCaseSource("SimpleDataSource")>]
member x.``SimpleTest`` (testData: SimpleRecord * int) =
let data, expected = testData
data.A + data.B
|> should equal expected
This test will run and pass as expected. However, changing the ToString
override to include a call to Guid.ToString()
will prevent the test from being run:
type SimpleRecord = { A: int; B: int }
override x.ToString() = x.A.ToString() + Guid.NewGuid().ToString()
With the above change, the test still appears in Test Explorer, but it will not be run. Even right-clicking on it and selecting Run Selected Tests will not execute the test. No build errors are reported.
I also experimented with using DateTime.ToString()
instead of Guid.ToString()
, but that also refuses to run:
type SimpleRecord = { A: int; B: int }
override x.ToString() = x.A.ToString() + DateTime.Now.ToString()
Why would calling Guid.ToString()
or DateTime.ToString()
within the ToString
override on the type being tested result in the test not running?