The XUnit code below has a warning that _someClass doesn't have a value set, however the value is set in the InitializerAsync() method.
public class XUnitTests : IAsyncLifetime
{
private SomeClass _someClass; // CS8618 warning
public Task DisposeAsync()
{
return Task.CompletedTask;
}
public Task InitializeAsync()
{
_someClass = new() { SomeProperty = "Hello World" };
return Task.CompletedTask;
}
[Fact]
public void Test1()
{
var x = 2;
}
}
NUnit has the NUnit3002 analyser that suppresses CS8618 warnings when the class member is set in the Setup() method, so I was wondering if XUnit could implement something similar?
NUnit code:
public class NUnitTests
{
private SomeClass _someClass; // no warning
[SetUp]
public async Task Setup()
{
_someClass = new() { SomeProperty = "SomeValue" };
}
[Test]
public void Test1()
{
Assert.Pass();
}
}
The XUnit code below has a warning that
_someClassdoesn't have a value set, however the value is set in theInitializerAsync()method.NUnit has the NUnit3002 analyser that suppresses CS8618 warnings when the class member is set in the
Setup()method, so I was wondering if XUnit could implement something similar?NUnit code: