Page 1 of 1

How to run Profiler with MSTest.exe

Posted: Fri Jul 23, 2021 12:31 pm
by LenaF
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.

Re: How to run Profiler with MSTest.exe

Posted: Sun Jul 25, 2021 7:11 pm
by Andreas Suurkuusk
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.

Re: How to run Profiler with MSTest.exe

Posted: Mon Jul 26, 2021 4:24 pm
by LenaF
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.

Re: How to run Profiler with MSTest.exe

Posted: Tue Jul 27, 2021 10:50 am
by Andreas Suurkuusk
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).
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.