microsoft / testfx

MSTest framework and adapter
MIT License
697 stars 250 forks source link

Code suppressor for nullability on TestContext property #3262

Closed Evangelink closed 1 month ago

Evangelink commented 1 month ago

Summary

Add a suppressor for the nullability warning on the TestContext property.

Background and Motivation

When enabling nullability analysis, the compiler will notify that the TestContext property can be nullable because it's not assigned a value. This is a false positive because MSTest will always assign this property a value before calling any method (after the constructor).

Many people are currently working around the issue using the following pattern:

[TestClass]
public class C
{
    public TestContext TestContext { get; set; } = null!
}

Proposed Feature

Add a code suppressor.

Alternative Designs

Allow TestContext to be injected through ctor (see #2039)