How to run Profiler with MSTest.exe

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
LenaF
Posts: 2
Joined: Thu Jul 22, 2021 3:27 pm

How to run Profiler with MSTest.exe

Post by LenaF » Fri Jul 23, 2021 12:31 pm

Hello
I have v5.7.21.0 Interprise Memory Profiler

Before that I ran my UI automation tests as
MSTest.exe /testsettings:..\AutoTest\Local.testsettings /testcontainer: AutoTest.Tests.UI.dll /Test:ProcedureEditorMpe.EditWaitActivityInMpTestProcedure

Now I need to add Memory verifications to my tests

I added SciTech.MemProfilerApi to my project

and I added /noisolation flag to run MSTest.exe:

MSTest.exe /noisolation /testsettings:..\AutoTest\Local.testsettings /testcontainer: AutoTest.Tests.UI.dll /Test:ProcedureEditorMpe.EditWaitActivityInMpTestProcedure

but I got
MemProfiler.IsProfiling = False
in my log file.

It looks like Memory Profiler wasn't loaded

What else should I add to my code to Initialize Memory Profiler in my tests, could you help me.

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

Re: How to run Profiler with MSTest.exe

Post by Andreas Suurkuusk » Sun Jul 25, 2021 7:11 pm

How do you start “mstest.exe”? In order to profile unit tests, the test runner needs to be started by .NET Memory Profiler. It’s not enough to add “SciTech.MemProfilerApi” to the project.

There are several ways to run tests under the profiler, e.g. using the standalone profiler, NmpCore, or the Visual Studio test runner. If you provide some additional information on how you plan to run your tests, I can help you with the best way to achieve this.
Best regards,

Andreas Suurkuusk
SciTech Software AB

LenaF
Posts: 2
Joined: Thu Jul 22, 2021 3:27 pm

Re: How to run Profiler with MSTest.exe

Post by LenaF » Mon Jul 26, 2021 4:24 pm

Hello Andreas,

Special script runs our UI tests automatically from command line, for example:

MSTest.exe /testsettings:..\AutoTest\Local.testsettings /testcontainer: AutoTest.Tests.UI.dll /Test:ProcedureEditorMpe.EditWaitActivityInMpTestProcedure

1. As I understand path using NmpCore is:

NmpCore.exe MSTest.exe /testsettings:..\AutoTest\Local.testsettings /testcontainer: AutoTest.Tests.UI.dll /Test:ProcedureEditorMpe.EditWaitActivityInMpTestProcedure?

And we should in this case run MStest.exe with /noisolation flag?

2. Could you clarify path using the standalone profiler?

Thank you.

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

Re: How to run Profiler with MSTest.exe

Post by Andreas Suurkuusk » Tue Jul 27, 2021 10:50 am

1. The NmpCore command looks fine, but there’s a risk that the actual test process doesn’t get profiled. Adding the “/noisolation” flag may help with this, but a better option would be to specify that all processes should be profiled. You can specify that all processes should be profiled by using the “/profileprocess:all” command line option. Note that this option should be provided to NmpCore and not mstest, so it must come before “MSTest.exe”, e.g.:

NmpCore.exe /profileprocess:all MSTest.exe /testsettings:..\AutoTest\Local.testsettings /testcontainer: AutoTest.Tests.UI.dll /Test:ProcedureEditorMpe.EditWaitActivityInMpTestProcedure

2. You can start your test using “Profile application” in the standalone profiler. You will need to enter the full path to “MSTest.exe” and specify the working directory to use, normally the directory where the test assembly is located. To make sure that any spawned processes are also profiled, select “All .NET Processes” under “Select processes to profile” (this is only available in the Enterprise edition).
ProfileMSTest.png
You may also find some additional information under this old forum post.

There’s also an option to create a project and use “Profile unit tests” as the launch type. However, this doesn’t support MSTest.exe and I’m not sure it will simplify things in your case.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests