What is the attribute in Xunit that's similar to TestContext in Visual studio tests?

谁都会走 提交于 2019-12-23 09:32:45

问题


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?


回答1:


There is no TestContext in XUnit.

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# code:

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


来源:https://stackoverflow.com/questions/40121043/what-is-the-attribute-in-xunit-thats-similar-to-testcontext-in-visual-studio-te

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!