在xUnit.net中等待测试设置代码中的任务吗? [英] Await Tasks in Test Setup Code in xUnit.net?
问题描述
确切的情况是,我正在使用Protractor.NET(AngularJS的Protractor E2E框架的.NET端口)进行E2E测试,我想发出一些Web请求(并且API-System.Net.Http.HttpClient
-具有所有异步功能/Task
方法)在我执行/声明之前安排测试,只需要对几个测试进行相同的安排即可.
The exact situation is I'm doing E2E tests with Protractor.NET (.NET port of AngularJS's Protractor E2E framework) and I would like to make some web requests (and the API -- System.Net.Http.HttpClient
-- has all Async/Task
methods) to Arrange my test before I Act/Assert, only I need to do this same Arrange-ing for several tests.
我将xUnit.net用作我的测试运行程序,他们使用接口(IUseFixture<T>
)来为每个灯具设置代码.如果有一个IAsyncUseFixture<T>
带有一个Task SetFixtureAsync(T t);
或类似的东西,那将是很好的.我认为这样的事情不存在.另外,我也不认为构造函数也可以使用await
,并且构造函数是在xUnit.net中每次测试执行相同代码块的唯一其他方法.
I'm using xUnit.net as my test runner they use an interface (IUseFixture<T>
) for per-fixture setup code. It would be nice if there was a IAsyncUseFixture<T>
that had a Task SetFixtureAsync(T t);
or something. I don't think such a thing exists. Additionally I don't think constructors can use await
either, and constructors are the only other way to execute the same block of code per-test in xUnit.net.
我有什么选择? .Result
?那不是不好的做法(僵局)吗?
What are my options? .Result
? Isn't that bad practice (deadlock)?
推荐答案
我刚使用.Result
.到目前为止,一切都很好.
I just went with .Result
. So far, so good.
这篇关于在xUnit.net中等待测试设置代码中的任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!