在xUnit.net中等待测试设置代码中的任务吗?

编程入门 行业动态 更新时间:2024-10-25 01:30:45
本文介绍了在xUnit中等待测试设置代码中的任务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

确切的情况是,我正在使用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用作我的测试运行程序,他们使用接口(IUseFixture<T>)来为每个灯具设置代码.如果有一个IAsyncUseFixture<T>带有一个Task SetFixtureAsync(T t);或类似的东西,那将是很好的.我认为这样的事情不存在.另外,我也不认为构造函数也可以使用await,并且构造函数是在xUnit中每次测试执行相同代码块的唯一其他方法.

I'm using xUnit 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.

我有什么选择? .Result?那不是不好的做法(僵局)吗?

What are my options? .Result? Isn't that bad practice (deadlock)?

推荐答案

我刚使用.Result.到目前为止,一切都很好.

I just went with .Result. So far, so good.

更多推荐

在xUnit.net中等待测试设置代码中的任务吗?

本文发布于:2023-11-16 10:02:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   测试   xUnit   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!