docs/articles/nunit-analyzers/NUnit1033.md
| Topic | Value |
|---|---|
| Id | NUnit1033 |
| Severity | Warning |
| Enabled | True |
| Category | Structure |
| Code | TestContextWriteIsObsoleteAnalyzer |
Direct Write calls should be replaced with Out.Write.
Future version of NUnit will first mark the .Write methods on TestContext
as Obsolete and eventually remove them.
This rule allows updating your code before the methods are removed.
The Write methods are simple wrappers calling Out.Write.
There is no wrapper for Error which always required to use TestContext.Error.Write.
Besides this being inconsistent, later versions of .NET added new overloads,
e.g. for ReadOnlySpan<char> and async methods like WriteAsync.
Instead of adding more and more dummy wrappers, it was decided that user code should use
the Out property and then can use any Write overload available on TextWriter.
Simply insert .Out between TestContext and .Write.
TestContext.WriteLine("This isn't right");
becomes
TestContext.Out.WriteLine("This isn't right");
Configure the severity per project, for more info see MSDN.
# NUnit1033: The Write methods on TestContext will be marked as Obsolete and eventually removed
dotnet_diagnostic.NUnit1033.severity = chosenSeverity
where chosenSeverity can be one of none, silent, suggestion, warning, or error.
#pragma warning disable NUnit1033 // The Write methods on TestContext will be marked as Obsolete and eventually removed
Code violating the rule here
#pragma warning restore NUnit1033 // The Write methods on TestContext will be marked as Obsolete and eventually removed
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit1033 // The Write methods on TestContext will be marked as Obsolete and eventually removed
[SuppressMessage][System.Diagnostics.CodeAnalysis.SuppressMessage("Structure",
"NUnit1033:The Write methods on TestContext will be marked as Obsolete and eventually removed",
Justification = "Reason...")]