<PackageReference Include="NUnit" Version="3.13.0" />

TextCapture

public class TextCapture : TextWriter
The TextCapture class intercepts console output and writes it to the current execution context, if one is present on the thread. If no execution context is found, the output is written to a default destination, normally the original destination of the intercepted output.
public TextCapture(TextWriter defaultWriter)

Construct a TextCapture object