Author : HASSAN MD TAREQ

Points to Note

  • xUnit creates class instance for each test
  • Test class constructor will be called per test
  • Use test class constructor for test setup
  • If you need TearDown, implement IDisposible and dispose method will be called per test

Setup and Teardown

public class FooTest : IDisposable
{
    private readonly Bar _sut;
    
    // setup
    public FooTest()
    {
        _sut = new Bar();
    }
    
    // teardown
    public void Dispose()
    {
        // Dispose here
    }

    [Fact]
    public void BeInexperiencedWhenNew()
    {            
        Assert.True(_sut.IsOk);
    }
}