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?
This method is decorated with the Fact attribute, which tells xUnit that this is a test.
xUnit uses the [Fact] attribute to denote a parameterless unit test, which tests invariants in your code. In contrast, the [Theory] attribute denotes a parameterised test that is true for a subset of data. That data can be supplied in a number of ways, but the most common is with an [InlineData] attribute.
Important note: xUnit.net uses the presence of the interface IClassFixture<> to know that you want a class fixture to be created and cleaned up. It will do this whether you take the instance of the class as a constructor argument or not.
Instead, intelligence is built in the xUnit framework so that it can locate the test methods, irrespective of the location of the tests. Verify the raise and raise assert, irrespective of the place in the code where the problem occurs. This is not an attribute but is an ideal replacement for the [SetUp] attribute.
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/"
}
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "environment.json");
string json = File.ReadAllText(path);
Configuration = JsonConvert.DeserializeObject<TestingConfiguration>(json);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With