0

Attempting to do some memory leak checks in my automation test using the following

  • nUnit 3.8.1
  • TestStack.White 0.13.3
  • dotMemory 3.0.20171219.105559

Launching my tests with the following console command, as outlined here.

dotMemoryUnit.exe "E:\nunit3-console.exe" -- "C:\Dev\White\bin\Debug\Automation.dll"

The tests (outlined below in mostly psuedocode) launches the application, grabs a snapshot, navigates into various sub pages, returns to the base page, adn then gets another snapshot so I can do a compare for survived objects. The snapshot comparison is done using the method outlined here

private const MemoryCheckPoint snapshot1

[ OneTimeSetUp ]
public void SetUp()
{
    // launch application, hook up with teststack.white
    LaunchApplication();
}

[ Test, Order(1) ]
public void GetSnapshot()
{
    snapshot1 = dotMemory.Check();
}

[ Test, Order(2) ]
public void DoStuff()
{
    //Many tests like this that test navigation from this page
    //making sure controls work and values are returned as expected
}

[ Test, Order (3) ]
public void CheckMemory()
{
    dotMemory.Check(memory =>
    {
        // Compare two checkpoints
        Assert.That(memory.GetDifference(snapshot1).GetSurvivedObjects
            (where => where.Type.Is<string>()).ObjectsCount, Is.EqualTo(0));
    });
}

[ OneTimeTearDown ]
public void CloseWindow()
{
    Application.Close();
}

The idea is that if there are any UI elements that don't get disposed of due to events etc, this should pick them up as survived objects, and then I can manually repeat the test later to track down the source of the problem.

However when I run the tests using the dotmemoryunit.exe console I get the following error.

1) Error : White.Tests.MemoryCheck.System.ArguementException : You are trying to compare the snapshot with itself at JetBrains.dotMemoryUnit.Kernel.dotMemory.Api.GetDifference< Snapshot snapshot1, Snapshot snapshot2>

Considering they're definitely different snapshots, I cannot figure out why this is failing.

The reason I'm using the console runner is because, for some reason, when I try to run the automation tests using the resharper test runner, they don't run and it just returns Inconclusive : test not run

user3265613
  • 355
  • 2
  • 14

1 Answers1

2

By default dotMemory Unit works in context of the "Test", you can think about it like at the very beginning of the test method there is a call DotMemoryUnitController.TestStart and at the very end DotMemoryUnitController.TestEnd. All data are only valid inside one "Test".

You can switch off this behaviour by specifying --no-instrumentation command line parameter and calling DotMemoryUnitController.TestStart and DotMemoryUnitController.TestEnd manualy how described in this article

Ed Pavlov
  • 2,353
  • 2
  • 19
  • 25
  • Magic, I'm finally getting results back, not the results I'm expecting, but at least it's progress. It's a shame they didn't make it more obvious though (unless I skipped over that bit accidently) – user3265613 Aug 03 '18 at 13:26
  • And it looks like my plan is a nogo. For some reason rather than getting snapshots of my application, it's grabbing memory snapshots of the testrunner stuff. Might be because this is being run through White... Guess I'll need to find a different way to test this stuff. – user3265613 Aug 03 '18 at 13:45
  • dotMemory Unit gets snapshot of the process where code of the test is running, if you run another process from the test dMU is not the tool of chose. – Ed Pavlov Aug 03 '18 at 14:39