Xunit 中与 Visual Studio 测试中的 TestContext 相似的属性是什么? [英] What is the attribute in Xunit that's similar to TestContext in Visual studio tests?

查看:25
本文介绍了Xunit 中与 Visual Studio 测试中的 TestContext 相似的属性是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在从 Visual Studio 测试迁移到 xunit.在 VStests 中,我们可以使用 TestContext 访问运行时测试参数.我希望在运行时使用 msbuild 从命令行提供的测试中设置一个全局变量.有人可以帮忙找出 xunit 中的 TestContext 等价物吗?

We are migrating from visual studio tests to xunit.. In VStests we can access run time test parameters using TestContext. I am looking to set a global variable in the tests supplied at run time from command line using msbuild. Can someone help in finding out the TestContext equivalent in xunit?

推荐答案

没有XUnit 中的 >TestContext.

在运行测试时我找不到处理环境参数的规范方法,所以我依赖于 JSON 文件.例如:

I could not find a canonical way to deal with environment parameters when running the tests, so I relied on a JSON file. E.g.:

{
  "Browser": "Chrome",
  "BasePath": "localhost:4200",
  "BaseApiPath": "http://localhost:50204/"
} 

C# 代码:

string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "environment.json");
string json = File.ReadAllText(path);
Configuration = JsonConvert.DeserializeObject<TestingConfiguration>(json);

这篇关于Xunit 中与 Visual Studio 测试中的 TestContext 相似的属性是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆