swathi_reddy
swathi_reddy

Reputation: 265

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

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?

Upvotes: 17

Views: 12569

Answers (1)

Alexei - check Codidact
Alexei - check Codidact

Reputation: 23078

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

Upvotes: 4

Related Questions