Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing F# async workflows with xUnit.net's Task support

I'm writing F# code and tests in xUnit 1.9.

For normal sync stuff, I simply return unit and all is well; but now, I'm migrating the sync innards to be async workflows.

In other words, my simple AAA is getting explicit Async usage pushed out into it as I refactor the system:

let [<Fact>] ``Can consume using NEventStore InMemory`` () = 
    let store = NesGateway.createInMemory ()

    let finalDirection = playCircuit store |> Async.RunSynchronously // <----- YUCK

    test <@ CounterClockWise = finalDirection @> 

To remedy this, I want to make the body of the test be async. However, to the best of my knowledge, xUnit.net only manages methods returning Task-derived types, and hence I need a safe way of having my async test body be wrapped suitably for xUnit.net's runner to pick it up and handle it appropriately.

What's the best way to express my above test ?

like image 876
Ruben Bartelink Avatar asked Sep 01 '14 11:09

Ruben Bartelink


People also ask

What does F stand for in testing?

F = variation between sample means / variation within the samples. The best way to understand this ratio is to walk through a one-way ANOVA example. We'll analyze four samples of plastic to determine whether they have different mean strengths. You can download the sample data if you want to follow along.

What is F-test in ANOVA?

ANOVA and F-tests assess the amount of variability between the group means in the context of the variation within groups to determine whether the mean differences are statistically significant.


1 Answers

As part of xUnit 2.2 Beta 3, @Brad Wilson has done the necessary to make it work natively directly. Hence one can now simply write:

let [<Fact>] ``Can consume NEventStore InMemory`` () = async {
    let store = NesGateway.createInMemory ()

    let! finalDirection = playCircuit store

    test <@ CounterClockWise = finalDirection @> }
like image 102
Ruben Bartelink Avatar answered Oct 19 '22 02:10

Ruben Bartelink