Xunit中与Visual Studio测试中的TestContext类似的属性是什么?

swa*_*ddy 6 c# xunit xunit.net

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

Ale*_*xei 4

TestContextXUnit 中没有

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

{
  "Browser": "Chrome",
  "BasePath": "localhost:4200",
  "BaseApiPath": "http://localhost:50204/"
} 
Run Code Online (Sandbox Code Playgroud)

C#代码:

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