Reputation: 59
I am running a few NUnit tests and want my each test case to run all assertions till the end of the block before quitting even if there are few assertion failures. I see that there is Assert.Multiple (https://github.com/nunit/docs/wiki/Multiple-Asserts) which can serve that purpose but I am getting an error:
No overloads match for method 'Multiple'. The available overloads are shown below. Possible overload: 'Assert.Multiple(testDelegate: TestDelegate) : unit'. Type constraint mismatch. The type 'unit' is not compatible with type 'TestDelegate' . Possible overload: 'Assert.Multiple(testDelegate: AsyncTestDelegate) : unit'. Type constraint mismatch. The type 'unit' is not compatible with type 'AsyncTestDelegate' . Done building target "CoreCompile" in project "NUnitTestProject1.fsproj" -- FAILED.
If I have my test like:
[<Test>]
let getResponseCode () =
let response = Request.createUrl Post "https://reqres.in/api/users"
|> Request.setHeader (ContentType (ContentType.create("application", "json")))
|> Request.bodyString """{
"name": "morpheus",
"job": "leader"}"""
|> HttpFs.Client.getResponse
|> run
Assert.Multiple(() =>
Assert.AreEqual(200,response.statusCode)
Assert.AreEqual(215,response.contentLength)
)
How should I write it so that it should not give me an error on using Assert.Multiple? Thanks in advance.
Upvotes: 2
Views: 408
Reputation: 1006
You need to use a lambda in here. The syntax you've used there is the C# syntax for a lambda, in F# the syntax is fun () -> ...
, so in your case it will look like
Assert.Multiple(fun () ->
Assert.AreEqual(200, response.StatusCode)
Assert.AreEqual(215, response.ContentLength)
)
Upvotes: 5