Use JustMock in MSBuild

11 posts, 1 answers
  1. Roland Vonk
    Roland Vonk avatar
    20 posts
    Member since:
    Jan 2004

    Posted 18 Sep 2012 Link to this post

    I'm trying to get JustMock working in an MSBuild unit test task. I keep getting the dreaded 'Profiler must be enabled' error.

    It works in Visual Studio 2012 using the ReSharper test runner. xUnit.net is used as unit testing framework. I'm calling a .msbuild file, which looks like this:

    <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <Import Project="C:\Program Files (x86)\Telerik\JustMock\Libraries\JustMock.targets" />
     
        <UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\packages\xunit.runners.1.9.1\tools\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit" />
     
        <Target Name="Build">
            <JustMockStart />
            <xunit Assembly="bin\Release\WebshopNG.Tests.dll" />
            <JustMockStop />
        </Target>
    </Project>

    Superfluously, before calling msbuild.exe I set the following environment variables:

    COR_ENABLE_PROFILING=0x1
    COR_PROFILER={b7abe522-a68f-44f2-925b-81e7488e9ec0}

    I keep getting the following error in the event log:

    .NET Runtime version 4.0.30319.17929 - Loading profiler failed.  COR_PROFILER is set to an invalid CLSID: '{b7abe522-a68f-44f2-925b-81e7488e9ec0}'.  HRESULT: 0x800401f3.  Process ID (decimal): 5576.  Message ID: [0x2502].

    I've tried re-registering the Telerik.CodeWeaver.Profiler.dlls, but that did nothing. Googling the error yields nothing concrete, so I'm at a loss where to start.
  2. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 20 Sep 2012 Link to this post

    Hi Roland,
    Thanks again for contacting us. Here are few things that you can do:

    1. You can try running it using JustMockRunner console app and see if that works. More information on this can be found at this post:
    http://www.telerik.com/help/justmock/scenarios-running-jm-profiler-outside-visual-studio.html

    2. Make sure that you have copied the Telerik.CodeWeaver.Api.DLL to the folder where Telerik.JustMock.DLL is located.

    3. Please also try configuring the tests in build server using code activity workflow that ships with Justmock. Details on this can be found here:

    http://www.telerik.com/help/justmock/integration-code-activity-workflow.html

    4. Finally, I will investigate more on this in coming days to see if doing the same in VS 2012 also fails my tests.


    Kind Regards
    Mehfuz
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  3. DevCraft R3 2016 release webinar banner
  4. Roland Vonk
    Roland Vonk avatar
    20 posts
    Member since:
    Jan 2004

    Posted 24 Sep 2012 Link to this post

    1. I tried running the tests with JustMockRunner. The tests still failed, and I got the following event in my event log:
    .NET Runtime version 4.0.30319.17929 - Loading profiler failed during CoCreateInstance.  Profiler CLSID: '{D1087F67-BEE8-4f53-B27A-4E01F64F3DA8}'.  HRESULT: 0x80040154.  Process ID (decimal): 11912.  Message ID: [0x2504].

    2. I did and now I got a different message in the event log when running it from MSBuild:
    .NET Runtime version 4.0.30319.17929 - 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): 4016.  Message ID: [0x2516].

    3. We're not using TFS, we're using Mercurial and TeamCity for our SCC/CI needs.

    4. The tests do succeed in VS2012. It's just that they don't succeed outside of Visual Studio.
  5. Answer
    Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 27 Sep 2012 Link to this post

    Hi Roland,

    Thanks again for contact us. 

    Are you using a local system account in your build machine? In that regard, I would ask you to go to your environment variable settings and set JustMock instance variable in the following way:





    Next, restart the machine and see if that solves your issue. Here is the link the from Microsoft that has more information on it:


    http://support.microsoft.com/kb/821761#appliesto


    Kind Regards
    Mehfuz
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  6. Ilya
    Ilya avatar
    2 posts
    Member since:
    Sep 2012

    Posted 28 Sep 2012 Link to this post

    Hi,
    could you please explain how JUSTMOCK_INSTANCE variable works ? 
    Because I struggled one day with investigation how I can use justmock tests with profiler requests in my build process  without changing build processing such as adding JustMockRunner activity and after that I found that setting up JUSTMOCK_INSTANCE to "0" works when I set it for process who would start MsTest.exe 
  7. Roland Vonk
    Roland Vonk avatar
    20 posts
    Member since:
    Jan 2004

    Posted 28 Sep 2012 Link to this post

    Setting JUSTMOCK_INSTANCE to 0 proved to be the solution. I was able to run the tests in the stand-alone test runner and in MSBuild on my machine. I set those variables in the TeamCity configuration, and JustMock now runs perfectly on our build server. Thanks!
  8. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 02 Oct 2012 Link to this post

    Hi Ronald,

    It's great to hear that JustMock is now running perfectly in your build machine. Should you find any other issues please don't hesitate to contact us. 


    Kind Regards
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  9. Mohd
    Mohd avatar
    13 posts
    Member since:
    Jan 2013

    Posted 05 Jun 2013 Link to this post

    HI,
    I too need have the need of running the unit test case from msbuild using mstest in TFS. We want to use mstest specifically in the TFS 2010. So . My test case running perfectly fine from Visual 2010 by enabling profiler on from the Telerik menu in visual studion 2010.


    Can you help me to get the step of configuring the  existing TFS build definition so that profiler is enabled. As of now the error is profiler need to enabled.

    Thanks
    Mohd Moyeen
    mohd.moyeen@allscripts.com
  10. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 05 Jun 2013 Link to this post

    Hi Moyeen,

    I have replied to you in forum thread with ID 701028.

    Regards,
    Kaloyan
    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.
  11. Brian Fu
    Brian Fu avatar
    6 posts
    Member since:
    Jan 2010

    Posted 28 Jan 2014 in reply to Kaloyan Link to this post

    Hi Kaloyan,
        How do I find the solution in forum thread ID - 701028?

    Thanks.
  12. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 30 Jan 2014 Link to this post

    Hi Brian,

    In order to integrate JustMock inside your build process, please check our integration articles. There are workflows about configuring JustMock for different TFS version, using code activities or just MSBuild Tasks.

    However, if the above mentioned guides do not help you out, please share what the exact issue is and we will be happy to assist you further.

    As an addition, you could check this article for known issues that may cause you troubles.

    I hope this helps.

    Regards,
    Kaloyan
    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
DevCraft R3 2016 release webinar banner