c# - Xunit 中类似于 Visual studio 测试中的 TestContext 的属性是什么?

标签 c# xunit xunit.net

我们正在从 visual studio 测试迁移到 xunit。在 VStests 中,我们可以使用 TestContext 访问运行时测试参数。我希望在运行时使用 msbuild 从命令行提供的测试中设置全局变量。有人可以帮助找出 xunit 中的 TestContext 等效项吗?

最佳答案

There is no TestContext in XUnit .

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

{
  "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);

关于c# - Xunit 中类似于 Visual studio 测试中的 TestContext 的属性是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40121043/

相关文章:

c# - 如何解析包含 "17th"或类似后缀的日期字符串?

c# - 扩展 xUnit.NET 以在处理类和定位测试方法时使用自定义代码

c# - xUnit.net:全局设置+拆卸?

unit-testing - 如何使用VS2015 Preview运行xUnit单元测试?

c# - 从数据库中打开 word 文档(保存为二进制文件)

c# - 在组合框中的绑定(bind)项目上使用转换器

c# - 获取具有最新值的对象的不同列表

unit-testing - 如何对 ActionFilterAttribute 进行单元测试

nunit - 运行长时间运行的 NUnit/xUnit 测试,这样它们就不会阻塞其他测试

c# - Specflow 插件 : Generation error: Missing [assembly:GeneratorPlugin] attribute in