Can't get DotMemory Unit Tests working. "xUnit does not capture the standard output stream . . ."

I'm trying to use DotMemory with xUnit in unit tests. My simple example is below. I select "Run Unit tests under dotMemory runner . . ." and get an error.

I have no trouble writing to _output (examples are removed from this simplified test). It compiles, I have the latest NuGet package installed and everything updated as of the last five minutes. Any help would be great.

Here is my simple example:

using Xunit;
using Xunit.Abstractions;
using JetBrains.dotMemoryUnit;

namespace My.Tests
{
    public class DotMemoryTests
  {
      private ITestOutputHelper _output;

      public DotMemoryTests(ITestOutputHelper output)
      {
         _output = output;
      }

      [Fact]
      [DotMemoryUnit(FailIfRunWithoutSupport = true)]
      public void DotMemoryTest()
      {
      DotMemoryUnitTestOutput.SetOutputMethod(_output.WriteLine);
         Assert.True(true);
      }
    }
}

Here is my error:

DotMemoryUnitException
xUnit does not capture the standard output stream which is used by dotMemory Unit to report issues and save workspaces.
Use JetBrains.dotMemoryUnit.DotMemoryUnitTestOutput.SetOutputMethod to link dotMemory Unit with xUnit ITestOutputHelper
or suppress this exception by applying JetBrains.dotMemoryUnit.SuppressXUnitOutputExceptionAttribute to the assembly.
Suppressing the exception does not prevent dotMemory Unit from saving profiling data

Stack trace:

at JetBrains.dotMemoryUnit.ClientController.AttributeHelper.AssertxUnitOutput(MethodBase method)
at JetBrains.dotMemoryUnit.ClientController.DotMemoryUnitClient.TestStart(MethodBase testMethod)

at JetBrains.dotMemoryUnit.Client.ReflectionExtension.Invoke(Object instance, MethodBase method, Object[] args)
at JetBrains.dotMemoryUnit.Controller.TestController.TestStart()
at My.Tests.DotMemoryTests.DotMemoryTest() in C:\My.Tests\DotMemoryTests.cs:line 22
1 comment
Comment actions Permalink

Hi,

Try to set dotMemory Unit output method in the class constructor instead of test method:

using Xunit;
using Xunit.Abstractions;
using JetBrains.dotMemoryUnit;

namespace My.Tests
{
    public class DotMemoryTests
  {
      private ITestOutputHelper _output;

      public DotMemoryTests(ITestOutputHelper output)
      {
         _output = output;
      DotMemoryUnitTestOutput.SetOutputMethod(_output.WriteLine);

      }

      [Fact]
      [DotMemoryUnit(FailIfRunWithoutSupport = true)]
      public void DotMemoryTest()
      {
         Assert.True(true);
      }
    }
}

 

0

Please sign in to leave a comment.