我正在xUnit 1.9中编写F#代码和测试。
对于普通的同步内容,我只返回unit
,一切都很好;但是现在,我正在将同步内部迁移为async
工作流程。
换句话说,我的简单AAA是在重构系统时将明确的Async
用法插入其中:
let [<Fact>] ``Can consume using NEventStore InMemory`` () =
let store = NesGateway.createInMemory ()
let finalDirection = playCircuit store |> Async.RunSynchronously // <----- YUCK
test <@ CounterClockWise = finalDirection @>
为了解决这个问题,我想使测试的主体为
async
。但是,据我所知,xUnit.net仅管理返回Task
派生类型的方法,因此,我需要一种安全的方式来适当包装我的async
测试主体,以供xUnit.net的运行者使用并适当处理它。 。表达以上测试的最佳方法是什么?
最佳答案
作为xUnit 2.2 Beta 3的一部分,@ Brad Wilson已完成the necessary to make it work natively directly。因此,现在可以简单地写:
let [<Fact>] ``Can consume NEventStore InMemory`` () = async {
let store = NesGateway.createInMemory ()
let! finalDirection = playCircuit store
test <@ CounterClockWise = finalDirection @> }
关于unit-testing - 使用xUnit.net的任务支持测试F#异步工作流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25605130/