MemAssertion methods do not work for MSTest UIAutomation

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
Markus Sp

MemAssertion methods do not work for MSTest UIAutomation

Post by Markus Sp » Thu Sep 13, 2012 2:16 pm

We d´like to run the memprofiler to check for memory leaks on an automated regular base via UIAutomation. For this reason we integrated memoryprofiler to an existing UIAutomation unit test which is based on the MS Coded UI Test Framework (without using the action recorder).

As we can see via the TestResults of MSTest the memprofiler is running but cannot detect any objects in the target application. Instead of an exception message or any other usefull logging message the memprofiler returns all assert checks with true, which is in fact wrong.

The CodedUiTest is started correctly as I can see the target app executing successfully (UITest). Also we did the custom configuration on the UITests and Target Application in the App.config for <gcConcurrent enabled="false"/> and <supportRuntime version="v4.0.30319" />

Also we start MSTest.exe with the noisolation option:
/noisolation /testcontainer:Company.UITests.ProjectA.Tests.dll /test:CreateDocument /testsettings:Local.testsettings

Moreover the option for [Suspend thread until memory leak is handled] is already enabled.

In addition we added some Thread.Sleeps() into the UI Test before and after doing the asserts to give memprofiler more time to finish a snapshot somehow. But this also did not help. Switching from FastSnapShot to FullSnapShot had also no effect. MemAssertions still return always true.

Coded UI Test:

[TestMethod]
public void CreateDocument()
{
MemSnapShot refSnapShot = MemProfiler.FullSnapShot();

CustomUiHelper.WelcomeView.NewFile("testdocument");

using (MemAssertion.BeginAssertions())
{
Console.WriteLine("Is profiling: " + MemProfiler.IsProfiling);

AssertionsDefinition ad = new AssertionsDefinition();
ad.MaxInstances("Company.Presentation.Views.WelcomeView", true, 0);
ad.NoInstances("Company.Presentation.Views.WelcomeView");
ad.NoInstances("Company.Domain.DocumentRoot");
ad.MaxInstances("Company.Domain.DocumentRoot", true, 0);

bool assertResult = MemAssertion.Assert(refSnapShot, ad);
Assert.IsTrue(assertResult);
Console.WriteLine("memtests were: " + assertResult);
}
}

Andreas Suurkuusk
Posts: 1029
Joined: Wed Mar 02, 2005 7:53 pm

Re: MemAssertion methods do not work for MSTest UIAutomation

Post by Andreas Suurkuusk » Thu Sep 13, 2012 8:07 pm

If I understand you correctly, you are running your UI tests under MSTest, which is started using the profiler. And the UI that is tested is running under a separate process, "UITest". Is that correct?

If that's the case, the UITest process is not being profiled and the UI class instances (e.g. "Company.Presentation.Views.WelcomeView" and "Company.Domain.DocumentRoot") are not created in the profiled process. Therefore the assertions will not fail (if the specified type is not found, the NoInstances and MaxInstances assertions will always succeed*).

To check that the UI class instances are correctly GCed, you need to run the "UITest" process under the profiler, instead of "MSTest". Unfortunately, this also requires that you perform the assertions within the "UITest" process, which is probably not what you want.

* Even though it is correct that there are no instances of a type that cannot be found, it is likely that this is not intentional. If the type is missing, you would probably want to log it as an error. For a future version of the profiler, we will consider adding an option to throw an exception or raise an event if the assertion includes missing types.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests