This is a migrated thread and some comments may be shown as answers.

VS2017 - Analyze Code Coverage - ElevatedMockingException

5 Answers 299 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 20 May 2017, 01:56 AM

Sorry if this is a noob question on JustMock, but I'm still learning the package.  

 

VS 2017 Enterprise 15.2(26430.6) Release
.NET Framework 4.6.01586
XUnit.net 2.2.0
JustMock 2017.2.502.1

 

Created a unit test for testing an email module where I'm mocking the SmtpClient to keep it from actually sending emails in unit tests.  When I run the tests either all together or individually, they run properly.  When I attempt to use the Test->Analyze Code Coverage, several of them fail with:

Message: Telerik.JustMock.Core.ElevatedMockingException : Cannot mock 'Void Send(System.Net.Mail.MailMessage)'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* {9317ae81-bcd8-47b7-aaa1-a28062e41c71} (from process environment)
Disable the profilers or link them from the JustMock configuration utility. Restart the test runner and, if necessary, Visual Studio after linking.

I've tried some of the suggestions I've found in other forum topics like disabling Intellitrace, running VS elevated and enabling the VS2015 Intellitrace option in the JustMock Options menu.  None of these combinations appear to make any difference.  As it is, I'm unable to view code coverage using these unit tests which limits the usability.

 

Here's the code that passes except under Analyze Code Coverage:

var log = Mock.Create<ILog>();
           Mock.Arrange(() => log.InfoFormat(EMailModule.Properties.Resources.Email_Send_log_SendingMessage,
               _validSubject)).OccursAtLeast(1);
 
           var smtpClient = Mock.Create<SmtpClient>(Behavior.CallOriginal);
           Mock.Arrange(() => smtpClient.Send(Arg.IsAny<MailMessage>()))
               .IgnoreArguments()
               .IgnoreInstance()
               .DoNothing()
               .OccursOnce();
 
           var mail = new Email(log, _testSMTPServer);
           mail.Sender = new MailAddress(_validSender);
           mail.EmailAddressesTo.Add(new MailAddress(_validEmail));
           mail.Subject = _validSubject;
           mail.Send();
 
           Mock.Assert(smtpClient);
           Mock.Assert(log);

 

Anyone have any suggestions?  Is this a bug, a known issue with VS2017 and JustMock or just me being too new to JustMock a.k.a.I screwed something up?

 

 

5 Answers, 1 is accepted

Sort by
0
Kamen Ivanov
Telerik team
answered on 25 May 2017, 10:29 AM
Hello David,

Thank you for contacting us about this issue. We tested it on our side and indeed, JustMock and the profiler used for code coverage within Visual Studio 2017 are not automatically being linked. The good news is that you should be able to fix this, by adding the VS Profiler GUIDs in the JustMcok configuration file. To do this, you can follow the next steps:
  1. Close all running instances of Visual Studio on your computer.
  2. Start notepad as an administrator.
  3. In it, open the Telerik.JustMock.Configuration.exe.config file (normally found under the "C:\Program Files (x86)\Telerik\JustMock\Libraries" folder)
  4. There, add the following lines under ComRegistrationHijackedProfilersā€‹:
    Copy Code
    <add product="Visual Studio 2017 Code Coverage/IntelliTrace" name="IntelliTrace 2017" profilerGuid="9317AE81-BCD8-47B7-AAA1-A28062E41C71"/>
    <add product="Visual Studio 2017 Code Coverage/IntelliTrace" name="IntelliTrace 2017 64-bit" is64bit="true" profilerGuid="9317AE81-BCD8-47B7-AAA1-A28062E41C71"/>
  5. Next, add the following line, under MiscellaneousProfilersā€‹:
    Copy Code
    <add product="Visual Studio 2017 Code Coverage/IntelliTrace" name="vstest.discoveryengine 2017 massager" implementation="DiscoveryEngineMassager" parameter="32=IntelliTrace 2017; 64=IntelliTrace 2017 64-bit"/>
  6. Save the file in notepad.
  7. Run, the JustMock Configuration tool (C:\Program Files (x86)\Telerik\JustMock\Libraries\Telerik.JustMock.Configuration.exe)
  8. Select the Visual Studio 2017 Code Coverage/ IntelliTrace checkbox.
  9. Finally, check if both code coverage and JustMock elevated tests will work on your side.

Further, we plan to release offical support for VS2017 code coverage and performance profiling with the next JustMock version.

I hope this helps.

Regards,
Kamen Ivanov
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
David
Top achievements
Rank 2
answered on 25 May 2017, 07:37 PM
Will these manual edits to the JustMock .config file cause any issues when the next update is released?  Any things I will need to take care of manually at that point or will it simply overwrite and it will take care of itself?
0
Kamen Ivanov
Telerik team
answered on 26 May 2017, 10:37 AM
Hi David,

These manual changes are totally safe and you don't have to do anything manually when installing future versions of JustMock.

If you want to make sure you can easily restore the previous configuration you could keep a backup of the edited file.

Regards,
Kamen Ivanov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Accepted
Kamen Ivanov
Telerik team
answered on 31 May 2017, 07:51 AM
Hello David,

I'm writing you to let you know that we have released an official internal build wit support for MSTest v2 and integration with code coverage & intellitrace for visual studio 2017.

You can download it from your Telerik account -> Downloads -> ProgressĀ® TelerikĀ® JustMock.

Regards,
Kamen Ivanov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
David
Top achievements
Rank 2
answered on 04 Jun 2017, 03:03 PM

The latest update fixed it and it works fine.  Took me a while to get back to this as I had to transition to a new machine (always a challenge to get things the way you like them).  With the internal build, the problem is resolved.

 

Thanks!

Tags
General Discussions
Asked by
David
Top achievements
Rank 2
Answers by
Kamen Ivanov
Telerik team
David
Top achievements
Rank 2
Share this question
or