2

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.

Check the screenshot of an error here:

asked Jun 15, 2020 at 12:50

1 Answer 1

5

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)
)
answered Jun 15, 2020 at 12:58
Sign up to request clarification or add additional context in comments.

1 Comment

I gave a shot to this earlier but not sure why it didn't work then. Thanks working fine now :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.