Skip to content

Commit

Permalink
Enable trace writer fix for NUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Mar 14, 2024
1 parent 24133f3 commit 49326bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/NUnitTestAdapter/NUnit.TestAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Testing.Extensions.VSTestBridge" Version="1.0.2" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3" PrivateAssets="All" />
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="nunit.engine" Version="3.15.5" />
<PackageReference Include="TestCentric.Metadata" Version="2.0.0" Aliases="TestCentric" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.Messages;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using NUnit.Engine;
using NUnit.Engine.Internal;

using NUnit.Framework.Internal;

namespace NUnit.VisualStudio.TestAdapter.TestingPlatformAdapter
{
Expand Down Expand Up @@ -83,16 +83,14 @@ private static void PatchNUnit3InternalLoggerBug()
return;
}

// TODO: Uncomment this line when InternalsVisibleTo is set up.
// var nopWriter = new InternalTraceWriter(new StreamWriter(Stream.Null));
var nopWriter = new InternalTraceWriter(new StreamWriter(Stream.Null));

// Initialize log level to be Off (see issue https://github.com/microsoft/testanywhere/issues/1369)
// because we don't have settings from the request available yet, and the internal tracer is static, so it would set to the
// level that is set by the first request and always keep it that way.
//
// Alternatively we could hook this up to a ILogger, and write the logs via a TextWriter.
// TODO: Uncomment this line when InternalsVisibleTo is set up.
// InternalTrace.Initialize(nopWriter, InternalTraceLevel.Off);
InternalTrace.Initialize(nopWriter, InternalTraceLevel.Off);

// When we allow the trace level to be set then we need to set the internal writer field only when the level is Off.
// In that case you will need to do something like this:
Expand All @@ -104,9 +102,8 @@ private static void PatchNUnit3InternalLoggerBug()
// traceWriterField.SetValue(null, nopWriter);
// }

// TODO: Uncomment these lines when InternalsVisibleTo is set up.
// FieldInfo traceWriterField = typeof(InternalTrace).GetField("traceWriter", BindingFlags.Static | BindingFlags.NonPublic)!;
// traceWriterField.SetValue(null, nopWriter);
FieldInfo traceWriterField = typeof(InternalTrace).GetField("traceWriter", BindingFlags.Static | BindingFlags.NonPublic)!;
traceWriterField.SetValue(null, nopWriter);

initialized = true;
}
Expand Down

0 comments on commit 49326bd

Please sign in to comment.