question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow asynchronous tests to run on Task<'a>

See original GitHub issue

That FsCheck can run asynchronous tests is one of its major advantages over competitors. It’d be nice, however, if it could run methods/actions that return Task<'a> instead of simply Task.

Particularly, with the new task computation expression, one can easily write an asynchronous (integration) test, but even if such a test body ends with an assertion, the expression has the type Task<unit>, rather than Task.

One can get around this issue by upcasting the expression with :> Task. If, however, one wishes to avoid adding an extra line of code for only that purpose, one runs into this issue.

If, currently, one tries to pass a Task<unit> to Prop.forAll if compiles fine, but fails at run time with this error message:

No instances of class FsCheck.Testable+ITestable`1[T] for type
System.Threading.Tasks.Task`1[Microsoft.FSharp.Core.Unit]

This is on FsCheck.Xunit 3.0.0-beta2.

Since Task<'a> derives from Task is seems to me that a fix should be a fairly straightforward.

If you agree that such a fix is desired, I may try my hand at it myself. (I’ve been away from contributing to FsCheck for years, now, so I hope I’m not biting off more than I can chew.)

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
kurtschelfthoutcommented, Jul 23, 2023

Released in 3.0.0-rc1.

Also merged fscheck3 branch to master.

1reaction
kurtschelfthoutcommented, Jul 1, 2023

@bartelink yes, I think it’s time for that. I’ll probably just do 3.0.0 even. If the other plans ever materialize, there’ll just have to be another version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asynchronous Tests and Expectations
When the asynchronous task completes, perform assertions to confirm that the task's actual results meet your expected results. If your test encounters a...
Read more >
Consuming the Task-based Asynchronous Pattern
Language-based asynchronous support hides callbacks by allowing asynchronous operations to be awaited within normal control flow, and compiler- ...
Read more >
Async Programming - Unit Testing Asynchronous Code
Their test runners can cope with async Task tests and await the completion of the thread before they start to evaluate the assert...
Read more >
Unit testing Swift code that uses async/await
Let's take a look at how to call async APIs within our unit tests, and also how async/await can be a great testing...
Read more >
Asynchronous Testing in Swift - Semaphore CI
In this article, we'll look at how you can use asynchronous testing for functions that return data after a variable amount of time....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found