You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using various functions within the library, I think it would be nice if we could add support for async/task test cases. The main two I can think of are testParam and testFixture. If there are other functions that already support this or there is a better way to do this with existing functionality, I would appreciate any insight you have.
Comments
I know I reused the same code for both examples but I just wanted a quick way to illustrate the async/task ergonomics. I realize a http client factory may not be the best use of one or both of these functions.
testParam Example
Current Support
openExpectoopenSystem.ThreadingopenMicrosoft.AspNetCore.Mvc.TestingopenMyApi.Api[<Tests>]letallTests=letfactory=new WebApplicationFactory<Startup>()
testList "MyApi Integration Tests"[
testParam (factory.CreateClient())["GET /",fun client ()->task{let!response= client.GetAsync("/")let!body= response.Content.ReadAsStringAsync()
Expect.equal "Hello World!" body "Expected 'Hello World!'"}|> Async.AwaitTask // currently have to do this|> Async.RunSynchronously // currently have to do this]|> List.ofSeq
|> testList "Routing Tests"][<EntryPoint>]letmain args =letcts=new CancellationTokenSource()
runTestsWithCLIArgsAndCancel cts.Token [| Summary |] args allTests
Ideal Support
Add support for testParamAsync and testParamTask to allow creating the testCaseAsync and testCaseTask under the hood.
While testFixtureAsync is an existing function, it only allows for asynchronous setup, I believe.
openExpectoopenSystem.ThreadingopenMicrosoft.AspNetCore.Mvc.TestingopenMyApi.Api[<Tests>]letallTests=letfactory=new WebApplicationFactory<Startup>()letwithClient f ()=use client = factory.CreateClient()
f client
testList "MyApi Integration Tests"[yield! testFixture withClient ["GET /",fun client ->task{let!response= client.GetAsync("/")let!body= response.Content.ReadAsStringAsync()
Expect.equal "Hello World!" body "Expected 'Hello World!'"}|> Async.AwaitTask // currently have to do this|> Async.RunSynchronously // currently have to do this]][<EntryPoint>]letmain args =letcts=new CancellationTokenSource()
runTestsWithCLIArgsAndCancel cts.Token [| Summary |] args allTests
Ideal Support
This one may be weird to name if it is desired since we have testFixture and testFixtureAsync. In order to not break existing functionality, does it make sense to add async/task after test to show the signature of the test and then have async/task after fixture to show the signature of the fixture?
It looks like testParam indeed lacks async and task variants.
This is an inconsistency worth patching
However, it appears that testFixtureAsync and testFixtureTask behave in the preferred way you describe: they respectively take async and task types who's evaluation is managed by the library. See the documentation, testFixtureTask tests, and some testFixtureAsync tests
Suggestion
When using various functions within the library, I think it would be nice if we could add support for async/task test cases. The main two I can think of are
testParam
andtestFixture
. If there are other functions that already support this or there is a better way to do this with existing functionality, I would appreciate any insight you have.Comments
I know I reused the same code for both examples but I just wanted a quick way to illustrate the async/task ergonomics. I realize a http client factory may not be the best use of one or both of these functions.
testParam Example
Current Support
Ideal Support
Add support for
testParamAsync
andtestParamTask
to allow creating thetestCaseAsync
andtestCaseTask
under the hood.testFixture Example
Current Support
While
testFixtureAsync
is an existing function, it only allows for asynchronous setup, I believe.Ideal Support
This one may be weird to name if it is desired since we have
testFixture
andtestFixtureAsync
. In order to not break existing functionality, does it make sense to add async/task aftertest
to show the signature of the test and then have async/task after fixture to show the signature of the fixture?Notes
I am willing to try and add the necessary support if we think this would be beneficial to add to the library.
The text was updated successfully, but these errors were encountered: