Mock.IsProfilerEnabled is False when running tests

4 posts, 0 answers
  1. Pablo
    Pablo avatar
    2 posts
    Member since:
    Mar 2013

    Posted 27 Jun 2013 Link to this post

    Hello,

    I'm trying to use the licensed JustMock version for developing some unit tests.

    I was having some issues when running existing unit tests (created by other people on the project), as the error: "Telerik.JustMock.MockException: Profiler must be enabled to mock/assert target ..." kept appearing over and over. I tried registering the dlls for Profiles and it did succesfully, but I'm still getting the same problem. If I open the JustMock configuration, no Profile is available. If I check the Telerik menu in VS 2010, the profiler is enabled. These is the result of the process and environment variables I get:
    • ProcessID=7428
    • JUSTMOCK_INSTANCE=5716
    • COR_ENABLE_PROFILING=
    • COR_PROFILER=
    (last two variables in blank) Then I set the variables as you indicated in: http://www.telerik.com/community/forums/justmock/general-discussions/profiler-must-be-enabled-to-mock-error.aspx to:
    • JUSTMOCK_INSTANCE = 1
    • COR_ENABLE_PROFILING = 1
    • COR_PROFILER = {B7ABE522-A68F-44F2-925B-81E7488E9EC0}
    Close VS, reopen again. When reopening the project, I get first the following error: vs error.png Then, I close it and then I get the following error: vs error 2.png I realized this doesn't happen if I don't set the COR_ENABLE_PROFILING variable (VS doesn't show that error again if I delete that variable). Also, when trying to run some of the tests using JustMock, VS closes unexpectedly. What can I do to fix it? How can I make JustMock work with VS 2010? Thanks, Pablo.

  2. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 28 Jun 2013 Link to this post

    Hi Pablo,

    I definitely wouldn't recommend starting Visual Studio with the JustMock profiler attached to it like you do.

    From what you've told us:
    • The JustMock profiler is enabled from the JustMock menu;
    • The tests throw an exception that the profiler isn't enabled;
    ... I'm lead to believe that another profiler loads into the test process instead of the JustMock one. To debug the issue further, please do a regular test run with JM enabled only from the menu and open Event Log->Windows Logs->Application. There should be one or more events with Event ID 1022. If JM is loading correctly, then the events should read "Profiler CLSID: '{b7abe522-a68f-44f2-925b-81e7488e9ec0}'." near the end. If the profiler CLSID is different - then there is another profiler overriding JM.

    I speculate that Visual Studio 2010' IntelliTrace is the profiler overriding JM. If that's the case, I suggest you try the latest Internal Build of JustMock and use the JustMock Configuration utility to link JustMock with Visual Studio 2010 IntelliTrace.

    If you have any further information to share on the issue or any other questions, please don't hesitate to write us again.

    Regards,
    Stefan
    Telerik
    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
  3. DevCraft R3 2016 release webinar banner
  4. Pablo
    Pablo avatar
    2 posts
    Member since:
    Mar 2013

    Posted 28 Jun 2013 Link to this post

    Hello,

    I don't understand what you mean when you say that JustMock is already enabled when I open VS. I just installed it, and when opening VS it is always in Enabled in the menu, it doesn't matter if I had disabled that from the menu before for this to be activated when I open VS.


    I found some event logs for event ID 1022:

    * .NET Runtime version 4.0.30319.18034 - The profiler was loaded successfully.  Profiler CLSID: '{b7abe522-a68f-44f2-925b-81e7488e9ec0}'.  Process ID (decimal): 5360.  Message ID: [0x2507].
    * .NET Runtime version 4.0.30319.18034 - The profiler has requested that the CLR instance not load the profiler into this process.  Profiler CLSID: '{b7abe522-a68f-44f2-925b-81e7488e9ec0}'.  Process ID (decimal): 4792.  Message ID: [0x2516].
    * .NET Runtime version 2.0.50727.5466 - Failed to CoCreate profiler.

    This is the test I ran:

    [TestMethod]
    public void JustMockTest()
    {
    Assert.IsTrue(Mock.IsProfilerEnabled);
    }

    Any idea?

    Thanks,




  5. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 02 Jul 2013 Link to this post

    Hi Pablo,

    From the event log that you've sent us I can see that the JustMock profiler has successfully activated in some processes. The messages contain the PID of the profiled process (e.g. "Process ID (decimal): 5360"). Could you please double-check that when you start a test run, then an event 1022 with message containing "The profiler was loaded successfully." is generated and the PID in the event message is the same PID as the test runner process (QTAgent32 in your case, I presume). This way you will know for sure that the profiler activates within the test runner correctly.

    Also, please double-check that the version of the Telerik.JustMock.dll managed library that you have referenced in your project is exactly the same as the one installed alongside the profiler. Just to be sure, do a Rebuild of your project, delete the TestResults folder in your project folder and build the project again.

    Regards,
    Stefan
    Telerik
    Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Back to Top