Profiler must be enabled Error

27 posts, 0 answers
  1. Chris McNear
    Chris McNear avatar
    12 posts
    Member since:
    Feb 2010

    Posted 10 Feb 2012 Link to this post

    I recently upgraded from JustMock Free Q1 2011 to JustMock Free Q3 2011.  Since upgrading I am getting errors on some of my tests.
    The errors are as follows.
    Test method SPM150.Test.LogBenchmarkValueChangeTest.Test0020LogTransactionCalledWhenValuesDifferentCorrectParmetersVersion1 threw exception:
    Telerik.JustMock.MockException: Profiler must be enabled to mock/assert target SPM150ControllerTestBase.get_AssetsServiceMock() method.

    My take on this is that somehow JustMock thinks I am trying to use features that are only available in the Paid version....

    The way we have our tests architected is that each method in the code that needs to be tested corresponds to a TestClass with all the needed Unit Tests within that test class for testing that method and only that method.  We also have a TestClass which acts as our base class for all the other TestClasses for the methods within a particular class in code.  This base class goes ahead and Mocks most if not all of the external dependencies (just Mock.Create) that the tests might use within it's TestInitialize method.  this way each time a method runs its getting fresh mocks....

    So here is an example of the code.
    First the Base Class
    [TestClass]
        public class SPM150ControllerTestBase
        {
     
            public IAssetsService AssetsServiceMock { get; set; }
            public INavigationService NavigationServiceMock { get; set; }
            public ISPM150Service SPM150ServiceMock { get; set; }
            public IGlobalData GlobalDataMock { get; set; }
            public SPM150Controller Target { get; set; }
     
            [TestInitialize]
            public void TestInit()
            {
                AssetsServiceMock = Mock.Create<IAssetsService>();
                SPM150ServiceMock = Mock.Create<ISPM150Service>();
                NavigationServiceMock = Mock.Create<INavigationService>();
                GlobalDataMock = Mock.Create<IGlobalData>();
                Target = Mock.Create<SPM150Controller>(Behavior.CallOriginal, new object[] { AssetsServiceMock, SPM150ServiceMock, NavigationServiceMock, GlobalDataMock, null });
     
            }
     
        }


    Now The class for the method under test.  with a failing method...

    [TestClass]
       public class LogBenchmarkValueChangeTest : SPM150ControllerTestBase
       {
           private const string PassedSiteNumber = "12345";
           private const string PassedUserName = "Hi Bob!";
           private const string PassedPrefix = "EQ Item Update";
     
           
           [TestMethod]
           public void Test0020LogTransactionCalledWhenValuesDifferentCorrectParmetersVersion1()
           {
               var beforeValue = 100.0;
               var afterValue = 1002.0;
     
               var expectedActionString = "EQ List Item Benchmark value changed from [100.0] to [1002.0]";
     
               AssetsServiceMock.Arrange(asset => asset.LogTransaction(Arg.AnyString, Arg.AnyString, Arg.AnyString)).OccursOnce();
     
     
               Target.LogBenchmarkValueChange(PassedSiteNumber, afterValue, PassedUserName, PassedPrefix, beforeValue);
     
               AssetsServiceMock.Assert();
               Mock.Assert(() => AssetsServiceMock.LogTransaction(
                   Arg.Matches<string>(site => site == PassedSiteNumber),
                   Arg.Matches<string>(user => user == PassedUserName),
                   Arg.Matches<string>(actionString => actionString == expectedActionString)));
           }

       }


    Thank you


    Edit 1:  I was able to determine the issue is related to whether or not the "Paid" version is installed and enabled or not.  When I install the trial for the paid version and enable it the exception goes away and things run. I also understand now that you can't mix Fluent Mocking/Assertion with the non fluent its either one or the other for each test.

    Apparently something changed between Q1 2011 and Q3 2011 releases that make things we were doing completely fine in Q1 now require the paid version of Q3?  Any thoughts?

    I would really like to upgrade to the Q3 release as it provides better support for the Fluent Arranging/Asserting (in particular the Fluent Assert method actually lets you pass in parameters and expectations....)  But if our tests are breaking because we don't currently have the paid version I can't use it.


    Any ideas are greatly appreciated.
  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 13 Feb 2012 Link to this post

    Hi Chris,

    Thanks again for reporting the issue. I was able to reproduce the problem and fix  it (since this is a virtual method, JM should not raise such exception). The fix will be available in the coming Q1 build to be released this week.

    Hope this solves your problem.

    Kind Regards,
    Mehfuz
    the Telerik team

    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Andrew
    Andrew avatar
    125 posts
    Member since:
    Sep 2008

    Posted 08 Mar 2012 Link to this post

    I am also getting the profile error on the 'Mock.Arrange' statement but am not sure how to fix it

    Here is my test.
    [Test]
    public void Test_GetApplicantByEmailAddress()
    {
     
        string emailAddress = "test1@test.com";
     
        AdmissionsEM admissionsEM = Mock.Create<AdmissionsEM>();
        Mock.Arrange(() => admissionsEM.Applicants).ReturnsCollection(GetApplicants());
     
        AdmissionsBF admissions = new AdmissionsBF(admissionsEM);
        List<Applicant> applicants = admissions.GetApplicants(emailAddress);
     
        Assert.AreEqual(applicants.Count, 1);
        Assert.AreEqual(applicants[0].Email_add, emailAddress);
     
    }

  4. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 12 Mar 2012 Link to this post

    Hi Chris,

    Thanks again for contacting us. Since you are using ReturnsCollection which prepares your collection for mocking and that is done via profiler, you are getting the exception in this line:
    Mock.Arrange(() => admissionsEM.Applicants).ReturnsCollection(GetApplicants());

    However, if admissionsEM.Applications is a virtual property and returns IList{T} items then you can just use Returns instead of ReturnsCollection that is used for mocking IQueyrable / LINQ queries.

    Kind regards,
    Mehfuz
    the Telerik team

    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. Christiano
    Christiano avatar
    17 posts
    Member since:
    Dec 2008

    Posted 04 Jul 2012 Link to this post

    Hi there.

    I'm facing teh same problem here: Telerik JustMock free 2012 Q2. When I try to Mock a method from any class, the exception is raised. The code snippet:

    CalculoFormula c = Mock.Create<CalculoFormula>();
     
    RM.Fop.Calculos.Calculo calc = Mock.Create<RM.Fop.Calculos.Calculo>();
    calc.ParametrosExecucao = new RM.Fop.Interfaces.ParametrosExecucaoBase() {CodColigada =1};
    RM.Fop.ObjectModel.ObjectBase owner = new RM.Fop.ObjectModel.ObjectBase();
     
    RM.Fop.CalculosBase.FuncionariosBase funcs = new RM.Fop.CalculosBase.FuncionariosBase(null);
    calc.FuncionarioCorrente = Mock.Create<FuncionarioBase>(Constructor.Mocked);
    calc.FuncionarioCorrente.Chapa = string.Empty;
    Mock.Arrange(() => calc.LogWrite(Arg.IsAny<string>())).DoNothing(); // exception raised here

    I also noticed that I doesn't make any difference if JustMock is enabled or not: in both cases, the exception "Profiler must be enabled" is raised. Is there something I can do in order to fix this behavior?

    Thank you
  6. Richard
    Richard avatar
    6 posts
    Member since:
    Jan 2011

    Posted 05 Jul 2012 Link to this post

    I regularly have this error with the paid version of JM. Restarting Visual Studio usually fixes this and this error on that section of code does not return. I have not discovered any clues in the code that may be triggering this.

    I am using the May release of JM.
  7. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 06 Jul 2012 Link to this post

    Hi Chris,

    Thanks again for contacting us. Can you send me the project that contains the test you have copied to your post. May be it could be some specific case or check that is not correct in JustMock which is throwing the exception. If you send me project that has this exception and can be reproducible then I can debug further. 

    Here to note that JustMock profiler has changed in Q2 2012. Therefore, any old reference of Telerik.JustMock.DLL can lead to this exception as well.

    Kind Regards
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Jay
    Jay avatar
    5 posts
    Member since:
    Feb 2008

    Posted 26 Jul 2012 Link to this post

    I have the latest version, but using Reshaper to run the Unit Tests and I get the same error message. Here is the code

    namespace UnitTesting.Mocking
    {
        using System;
        using NUnit.Framework;
        using Telerik.JustMock;
     
        public interface IClientServerMockingTest
        {
            void CallMethod(string id, Action<string> status);
        }
     
        public class ClientServerMockingTest : IClientServerMockingTest
        {
            public void CallMethod(string id, Action<string> status)
            {
                status.Invoke("Worked");
            }
        }
     
        public class TestClass
        {
      
            [Test]
            public void TestMethod1()
            {
                var clientServer = Mock.Create<ClientServerMockingTest>();
     
                Action<string> action = Console.WriteLine;
     
                // Throws error : Telerik.JustMock.MockException : Profiler must be enabled to mock/assert target ClientServerMockingTest.CallMethod(String,Action`1)
                Mock.Arrange(() => clientServer.CallMethod("demo", action)).DoInstead((string id, Action<string> aciton) => aciton.Invoke("faked"));
     
                clientServer.CallMethod("demo", action);
            }
        }
    }
  9. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 31 Jul 2012 Link to this post

    Hi Jay,

    Thanks again for contacting us. 

    I tried it with TestDriven.Net and it is working as expected. I would recommend you to use either TestDriven.Net / JustCode test runner for mocks that utilize profiler capabilities. At this moment we don't support R# runner officially but working on it for a possible solution.


    Kind Regards
    Ricky
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. Robert
    Robert avatar
    3 posts
    Member since:
    Jun 2010

    Posted 14 Aug 2012 Link to this post

    Ricky,

    Can you give any sort of ETA on adding ReSharper test runner support? I'm really liking JustMock but not supprting the R# runner could be a dealbreaker...

  11. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 17 Aug 2012 Link to this post

    Hello Robert,

    I`m sorry to say, but at this point we are only considering of adding ReSharper test runner support, and for now we can`t give you estimated time, when or will it be integrated in JustMock. As Ricky mentioned, we would recommend you to use JustCode / TestDriven.Net runner support as they are fully supported in JustMock.

    All the best,
    Kaloyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  12. Alex
    Alex avatar
    3 posts
    Member since:
    Aug 2012

    Posted 19 Aug 2012 Link to this post

    I too am having issues with JustMock when using certain method calls on arrange.  Replacing return values seems to work however DoInstead is failing with profiler exception.  I am using Visual Studio 2010 and Jetbrains Code Coverage tool.  Being able to check my coverage is essential to writing effective unit tests.  Please look into this!

          
    [TestMethod]
    public void TestSendMailHtml()
    {
        var smtp = Mock.Create<SmtpClient>();
     
        Mock.Arrange(() => smtp.Send(Arg.IsAny<MailMessage>())).DoInstead(() => Console.WriteLine("Sending HTML Message"));
         
        var mailer = new Mailer(smtp);
        mailer.SendMail("Subject", "Body", true);
    }
  13. Mihail
    Admin
    Mihail avatar
    75 posts

    Posted 20 Aug 2012 Link to this post

    Hi Alex,

    The current JustMock version is incompatible with other profiling tools including JetBrains dotCover tool. I am sorry for the inconvenience. The next JustMock Q3 2012 version will be compatible though. Stay tuned :)

    All the best,
    Mihail
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  14. Christiano
    Christiano avatar
    17 posts
    Member since:
    Dec 2008

    Posted 23 Aug 2012 Link to this post

    Finally I've fixed it. And the solution is kinda weird...:

    * I have decompiled JustMockRunner in order to see what was the "magic" performed to make JustMock work properly. Then I have set the environment vars exactly like there.

    * Dont ask me why, but the procedure above was not enough... But after installing Microsoft Pex and Moles, everything worked fine throug Visual Studio. Now, if I remove the above settings, JustMock JustDoNotWork.

    Thank you

  15. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 29 Aug 2012 Link to this post

    Hi Christiano,
    It's great to hear that things are working at your end. However, it's pretty strange that you have to install moles to get it working. Also, in general JustMockRunner  is the recommended way to run tests in command line settings. 

    Kind Regards,
    Ricky
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  16. Christiano
    Christiano avatar
    17 posts
    Member since:
    Dec 2008

    Posted 30 Aug 2012 Link to this post

    Ricky,

    I have tried to reproduce the same situation in another workstation. So, I faced the problem again, but I could solve the problem without installing the PEX/MOLES. The trick is to manually set the environment variables as performed by JustMockRunner(decompiled):


    info.EnvironmentVariables["COR_ENABLE_PROFILING"] = "0x1";
    info.EnvironmentVariables[
    "COR_PROFILER"] = "{B7ABE522-A68F-44F2-925B-81E7488E9EC0}";
    info.EnvironmentVariables[
    "COMPLUS_ProfAPI_ProfilerCompatibilitySetting"] = "EnableV2Profiler";
    //info.EnvironmentVariables[
    "JUSTMOCK_INSTANCE"] = Process.GetCurrentProcess().Id.ToString();<br><div></div>


    I believe everybody knows how do declare those variables on windows settings. If not, here goes a brief instruction set about how to achieve it: http://www.itcsolutions.eu/2010/11/29/set-environment-variables-in-windows-7-for-java/ 

    After doing this, you have to restart Windows and run VS2010.

    Without this, JustMock doesn't work in visual studio (at least here, in my computers).

    Thank you
  17. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 04 Sep 2012 Link to this post

    Hi Christiano,

    Thanks again for your post. It's great that you solved it out. 

    To further investigate, please also check the application events log for possible errors. If the JustMock profiler is loaded then you should see an event with ID 1022 and type "Information". Please find the attached justmock_log_success.png file for reference. If the JustMock fails to load then you should see an event with ID 1022 and type "Error". Please find the attached justmock_log_error.png file for reference.

    In case you see the error 1022 I would recommend to register the profiler DLLs manually. You can run the following commands from command prompt as an administrator:

    regsvr32.exe C:\Program Files (x86)\Telerik\JustMock\Libraries\CodeWeaver\32\Telerik.CodeWeaver.Profiler.dll
    regsvr32.exe C:\Program Files (x86)\Telerik\JustMock\Libraries\CodeWeaver\64\Telerik.CodeWeaver.Profiler.dll

    I am also adding some points to your telerik account.

    Kind Regards, 
    Ricky
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  18. Jeroen Speldekamp
    Jeroen Speldekamp avatar
    30 posts
    Member since:
    Mar 2005

    Posted 03 Oct 2012 Link to this post

    Hi,

    I'm facing thesame problem, using the paid version of JustMock. But I only get these errors when I do a gated check-in.

    One of my test results that make the Gated check-in fail:

    Test method SwhBilling.Website.Test.Controllers.ServerControllerTest.CreateTest threw exception: 
    Telerik.JustMock.MockException: Profiler must be enabled to mock/assert target ServerViewModel.get_Articles() method.


    The test that fails:
    [TestMethod]
    public void CreateTest()
    {
        //Arrange
        Mock.Arrange(() => _facade.GetEnabledArticles)
            .Returns(_articles);
        Mock.Arrange(() => _serverModel.Articles)
            .Returns(new Collection<Article>());
     
        //Act
        _controller.Create();
     
        //Assert
        Mock.Assert(() => _facade.GetEnabledArticles, Occurs.Once());
    }

    The Method I'm testing:
    public ActionResult Create()
    {
        ServerModel.Articles.AddRange(Facade.GetEnabledArticles);
     
        return View(ServerModel);
    }
  19. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 05 Oct 2012 Link to this post

    Hi Jeroen,

    Thanks again for contacting us.  

    Please make sure that your gated checkin configuration has the appropriate profiler configuration in place.  To troubleshoot it, make sure that if it uses some build task then it properly turns on the profiler just before running the test using JustMockStart directive.


    Kind Regards
    RIcky
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  20. Jiti
    Jiti avatar
    12 posts
    Member since:
    Jul 2012

    Posted 19 Oct 2012 Link to this post

    Hi,

    I am using the paid version of JustMock version number 2012.1.608.2
    When I use Mock.NonPublic.Arrange I am getting the error "Telerik.JustMock.MockException: Profiler must be enabled to mock/assert target"

    How can I solve this?

    Thanks,
    Jiti
  21. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 22 Oct 2012 Link to this post

    Hi Jiti,

    Thanks again for contacting us.

    This can happen due to number of factors. Please check the application events log for more information. I would request you to check out this knowledge base article that should give you some pointers on this:

    http://www.telerik.com/support/kb/justmock/general/handling-the-profiler-must-be-enabled-exception-in-justmock.aspx

    Kind Regards
    Ricky
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  22. Chris
    Chris avatar
    21 posts
    Member since:
    Oct 2012

    Posted 29 Oct 2012 Link to this post

    To everyone who is still getting this message, I would like to give a few tips that I have picked up as I have been using JustMock.

    1. Make sure the methods are virtual!!! Even if this is an interface implementation method, make sure the actual method that implements is marked virtual.  I found that I received this error quite often when methods weren't marked as virtual, when I then enabled the profiler I would find that tests did not behave as I expected, and the debugging would be way out of whack.  Once I marked the methods as virtual I stopped getting this message and the debugger worked as expected.
    2. Make your properties (even automatic) virtual as well. Same as above, it just works better when everything is marked virtual.
    3. Use the Arrange methods rather than assignments in your unit tests, For whatever reason when you do a straight assignment to a mocked object or an item under test (even if marked with Behavior.CallOriginal) JustMock is doing some stuff behind the scenes to the object and things don't always get assigned properly.
    4. If you can avoid static and private methods, do so. I use internal for anything I need to hide.  This way I can use the InternalsVisibleTo attribute in my assemvlyInffo.cs file and things work much better without having to use the profiler.
    5. Only use DoNothing() on methods that are void. If there is a Returns() call that will cause the method to do nothing and return the value you assign, DoNothing() and Returns() seem to conflict with each other and things go a little wierd when using both on the same method.
    6. Don't forget the Behavior.CallOriginal on your "target" object (class under test).

    I hope this helps at least someone to get past some of these issues. I have found that many of my issues were due to the level of my understanding of the JustMock API and how I was attempting to use the API incorrectly.  As I have learned more, the issues I have been having tend to be more related to actual issues or more "complicated" difficulties (ex. mocking extension methods, and explicit assertion of those methods).

    If I can help anyone any further I will do my best to try.
  23. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 31 Oct 2012 Link to this post

    Hi Chris,

    Thanks a lot for your suggestions.

    I am adding some telerik points to your account because of that. However, if you are not using JustMock Lite then I would suggest to keep an eye on this knowledge base post:

    http://www.telerik.com/support/kb/justmock/general/handling-the-profiler-must-be-enabled-exception-in-justmock.aspx

    Kind Regards
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  24. Chris
    Chris avatar
    21 posts
    Member since:
    Oct 2012

    Posted 31 Oct 2012 Link to this post


    Thanks Mehfuz, I really appreciate it.  I have seen that KB article before and had gone through all those steps in the past.  Or at least I thought I had. Many of the issues we have had were related to us using the free version back in Q1 of 2011 and then trying to upgrade the versions as they were released.  Many times things that worked in older versions didn't work in the newer versions.  This is undoubtedly because we were/are doing things incorrectly when it comes to Mocking using JustMock in those projects, but it definitely added confusion.  I just wanted to point out some of the things that we realized we were doing wrong in our projects to hopefully help others.
  25. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 31 Oct 2012 Link to this post

    Hi Chris,

    Your steps are definitely helpful and glad that you shared them with the community. It will obviously help others in configuring JustMock.


    Kind Regards
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  26. Chris
    Chris avatar
    12 posts
    Member since:
    Nov 2012

    Posted 15 Nov 2012 Link to this post

    I'm trying to setup some continuous integration testing and we are using NUnit (the console). But, I'm still getting the error described in this post. Everything seems to run fine in Visual Studio with Resharper, but outside it does not.
  27. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 16 Nov 2012 Link to this post

    Hello Chris,

     Please concern to this knowledge base and follow the steps in it:
     - http://www.telerik.com/support/kb/justmock/general/handling-the-profiler-must-be-enabled-exception-in-justmock.aspx

     Also you could find a lot of information that can be helpful in this forum post.

     If the issue still remains after completing these steps, please contact us for further assistance.

    All the best,
    Kaloyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top