dreadwail
dreadwail

Reputation: 15409

Do xunit tests run in total isolation?

If I have a static class:

public static class Foo
{
    public static string Bar = "baz";
}

And inside a xunit test I do something like this (contrived):

public class FooTests
{
    [Fact]
    public void Bar_can_be_set_to_buz()
    {
        Foo.Bar = "buz";
    }

    [Fact]
    public void Some_other_test()
    {
        //Is Foo.Bar "buz", or is there isolation ?
    }
}

Is the external static class shared by both tests, or is there complete isolation between tests?

Upvotes: 2

Views: 1075

Answers (1)

Brad Wilson
Brad Wilson

Reputation: 70606

Each test gets a new instance of the test class. Any static state will shared amongst all tests.

Upvotes: 4

Related Questions