How do I run a test case with different environment variables in xUnit?

I would run the test case several times with different custom environment variables.

Example:

[Theory]
[InlineData(1)]
[InlineData(2)]
[MyEnvironmentData("foo", "bar", "baz")]
public void MyEnvironmentTest(int arg1)
{
  var foo=MyEnvironment.Get("foo");
  Assert.Contains(foo, new []{"bar", "baz"});
}

      

The test script must run four times:

  • arg1 = 1, MyEnvironment.Get ("Foo") = "bar"
  • arg1 = 1, MyEnvironment.Get ("Foo") = "baz"
  • arg1 = 2, MyEnvironment.Get ("Foo") = "bar"
  • arg1 = 2, MyEnvironment.Get ("Foo") = "baz"

There can also be many MyEnvironmentData attributes. In this case, all permutations must be tested.

I previously did this in xUnit.Net v1 using a custom TestClassCommand

one where I implemented my permutation logic in a method EnumerateTestCommands

and a custom TestCommand

one that will take care of setting environment variables before each test run and cleanup after. All other methods have been delegated to xUnit's own TestClassCommands and TestCommands.

What would be the best way to implement a similar setup in xUnit v2?

+3
c # xunit.net


source to share


No one has answered this question yet

Check out similar questions:

805
How do I get my .NET application to run under administrator control?
20
How to set up a sequence of test cases in xUnit
five
Extending xUnit.NET to use custom code when processing a class and finding test methods
five
XUnit.net captures the result of each test immediately after it runs
4
How to run XUnit tests using code
2
Assertion if two different objects have the same values ​​in a dynamic collection
1
Running XUnit tests with specific Traitname
1
Design-Time Attribute Requirements
1
Xunit.Net skipping tests due to duplicate ID
1
Running NUnit Test Cases with xUnit Test



All Articles
Loading...
X
Show
Funny
Dev
Pics