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

Why is the Enable/Disable the profiler an IDE setting?

11 Answers 838 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tormod
Top achievements
Rank 2
Tormod asked on 05 Aug 2010, 11:44 AM
Hi.
I am slightly confused by the JustMock integration with visual studio.

Will tests start failing if I disable the "Enable Profiler" setting?
How do I control this setting on the CI build server?

It seems to me that wether or not the JustMock library shall use the .NET profiler API should be an attribute or passed parameter in the individual test and not a global IDE setting. Then I should organize my tests so that I don't run long-running ones on the quick cycles.
The profiler should be dynamically loaded if the unit tests demanded the profiler. AFAICT, this information should be contained in the unit tests.

Why was the approach chosen to have this as a manual setting in the IDE? I want my testcode to be self specified. I don't want to explain to a colleague that the reason why my unit tests are failing on his computer is because of a setting. That's a definite no-no in TDD.

Why was this approach chosen?

11 Answers, 1 is accepted

Sort by
0
Chris
Telerik team
answered on 05 Aug 2010, 12:14 PM
Hi Tormod,
Thanks for bringing these questions up.

> Will tests start failing if I disable the "Enable Profiler" setting?

Only the "elevated" tests will fail if you disable JustMock from the Visual Studio menu. The "elevated" tests are those which mock static types and members, sealed types, non virtual members and so on. The other tests which mock interfaces, virtual members, etc. will not fail.
Actually the elevated tests might not fail at all, if you had already run the tests prior to disabling JustMock, as most of the test runners keep the test runner process alive after the first run and thus JustMock's profiler will be already enabled in the test runner process.

> How do I control this setting on the CI build server?

It depends on the CI server. We've provided integration tasks for MSBuild and NAnt and you can get more information here on how to use them:
http://www.telerik.com/help/justmock/integration-msbuild-tasks.html
http://www.telerik.com/help/justmock/integration-nant.html

You can also check this forum post on how to use JustMock in TFS 2010:
http://www.telerik.com/community/forums/justmock/general-discussions/setupstatic-mockexception-opps-there-were-some-error-intercepting-target-call.aspx#1259708

For other CI build servers you'll need to write a custom integration task specific for the build server which you're using. Generally this should be easy as the only thing you need to do is to set three environment variables before the build servers runs the tests. These are the variables and their respective values:

"COR_ENABLE_PROFILING", "0x1"
"COR_PROFILER", "{D1087F67-BEE8-4f53-B27A-4E01F64F3DA8}"
"COMPLUS_ProfAPI_ProfilerCompatibilitySetting", "EnableV2Profiler"

> The profiler should be dynamically loaded if the unit tests demanded the profiler. AFAICT, this information should be contained in the unit tests

Actually that's what we do. Should you have some issues with such scenario (tests mocking interfaces or virtual members which are failing with disabled profiler mode), please send us a separate support request because most probably this is a bug which need to fix.

Hope this infromation helps.

All the best,
Chris
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Shane Milton
Top achievements
Rank 2
answered on 15 Aug 2010, 07:03 PM
I'm confused, then. What does the enable/disable do, exactly?
0
Ricky
Telerik team
answered on 17 Aug 2010, 04:35 PM
Hi Shane Milton,

Enable / Disable acutally enables or disables the JustMock profiler for mocking concrete members. After disabling it from VS menu or if you un-checked the "integrate JustMock with visual studio" option during installation,  it will still be possible to mock virtual members , interfaces or non sealed classes  that is mocked using a dynamic proxy.

In other words, mocking such members does not require a profiler to be installed on the dev machine or on the production server. Also, does not require the MSBuild /NAnt tasks.

Greetings,
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Mihai
Top achievements
Rank 1
answered on 04 Apr 2011, 10:29 AM
In my test project I added a piece of code that enables JustMock programatically and it works fine:
        private static void EnableJustMock()
        {
            System.Environment.SetEnvironmentVariable("COR_ENABLE_PROFILING", "0x1");
            System.Environment.SetEnvironmentVariable("COR_PROFILER", "{D1087F67-BEE8-4f53-B27A-4E01F64F3DA8}");
            System.Environment.SetEnvironmentVariable("COMPLUS_ProfAPI_ProfilerCompatibilitySetting", "EnableV2Profiler");
        }

Unfortunately, this doesn't seem to work if I try to compile and run it on a machine without JustMock installed even though I've added the required .dll reference. Is there a way to make this possible?
0
Ricky
Telerik team
answered on 05 Apr 2011, 09:55 AM
Hi Mihai,
Thanks again for your query. Generally JustMock registers the profiler during installation but you can try registering the profiler DLL manually using the following command:

regsvr32.exe Telerik.CodeWeaver.dll

You should get a confirmation that the DLL registered successfully.  But you need to have admin privileges for that and need to make sure that you are using the correct assembly(x86/x64).

For my machine the path to CodeWeaver.DLL looks like:
%PROGRAMFILES% (x86)\Telerik\JustMock\Libraries\CodeWeaver\x64

Hope this information is useful.

Kind Regards,
Ricky
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Aaron Reed
Top achievements
Rank 1
answered on 06 Oct 2016, 05:02 PM

How can you dynamically enable the profiler?

I have tried all suggestions, including this as a pre-build step:

regsvr32.exe /s Telerik.CodeWeaver.Profiler.dll

I have experimented with this code, that also has no effect:

public static void EnableJustMockProfiler()
        {
            System.Environment.SetEnvironmentVariable("COR_ENABLE_PROFILING", "0x1");
            //System.Environment.SetEnvironmentVariable("COR_PROFILER", "{D1087F67-BEE8-4f53-B27A-4E01F64F3DA8}");
            System.Environment.SetEnvironmentVariable("COR_PROFILER", "{DC2D6321-28A9-4AB0-92FC-EBA40D6FF48F}");
            System.Environment.SetEnvironmentVariable("COMPLUS_ProfAPI_ProfilerCompatibilitySetting", "EnableV2Profiler");
        }

0
Svetlozar
Telerik team
answered on 11 Oct 2016, 01:46 PM
Hi,

Thank you for your feedback. 

You need to register the JustMock profiler component (using regsvr32) only once. You can either do it using the command line or installing JustMock using the msi installer on the build machine. The msi installer would call regsvr32. 

Once you have done that you just need to set 3 environment variables

JUSTMOCK_INSTANCE = 1 
COR_ENABLE_PROFILING = 1
COR_PROFILER = {B7ABE522-A68F-44F2-925B-81E7488E9EC0}

Please note that you are using the older GUID which is no longer valid. The important part here is that when the CLR loads it checks for these variables and attaches the profiler if they are set. You need to set these before the test runner process starts, because otherwise the CLR won't have the variables and thus won't load the profiler. I hope that makes sense. 

If you still have problems, don't hesitate to write back. We would need more information about your build in order to help.

Regards,
Svetlozar
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
Aaron Reed
Top achievements
Rank 1
answered on 14 Oct 2016, 08:16 PM

@Svetlozar - 

I change the initialization code to this (called at [ClassInitialize] method):

public static void EnableJustMockProfiler()
{
    System.Environment.SetEnvironmentVariable("JUSTMOCK_INSTANCE", "1");
    System.Environment.SetEnvironmentVariable("COR_ENABLE_PROFILING", "1");
    System.Environment.SetEnvironmentVariable("COR_PROFILER", "{B7ABE522-A68F-44F2-925B-81E7488E9EC0}");
}

 

I added the full path and call to the Telerik profiler in the regsvr32.exe pre-build event command line in the unit test project:

regsvr32 /s D:\source\Engineering\SharedLibraries\ThirdParty.Binaries\Telerik\JustMock.2016.3.914.2\CodeWeaver\64\Telerik.CodeWeaver.Profiler.dll

JustMock is fully installed on my development system.

No matter what I try, I cannot automate the activation of 'Enable Profiler'.  I really want this to work.

Any further ideas?

Thanks,
Aaron

0
Svetlozar
Telerik team
answered on 19 Oct 2016, 06:49 AM
Hello,

I am really sorry for the misunderstanding.

You need to set the environment variables before the test runner process starts, because otherwise the CLR won't have the variables and thus won't load the profiler.

Doing that in the ClassInitialize method is too late. The process has started and already running. Usually the approach is to add a build step before the test runner step that sets the environment variables. The important part is to have them when the test runner process starts. How to achieve that really depends on your build.

Let us know if you have any questions.  

Regards,
Svetlozar
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
Aaron Reed
Top achievements
Rank 1
answered on 19 Oct 2016, 10:22 PM

@Svetlozar - I see.  

That is unfortunate this setting is a part of the IDE.  Out of curiosity, do you have an example application that does this?  Would building a console app separately that runs in the pre-build step work through the IDE?  I would like to not think about flipping on the profiler all of the time.  I want to be in a unit test, press ctrl+R, ctrl+T and the target unit test runs without issue.

Aside from that, the build will need to do this as well in an automated fashion for the CI builds.  The unit test project we have is basically something that builds and executes simple unit tests.  Like many unit tests, we use mocks in some cases which need the profiler on.

0
Svetlozar
Telerik team
answered on 24 Oct 2016, 03:39 PM
Hi,

That is unfortunate this setting is a part of the IDE. 

That setting only sets and unsets the environment variables. That is how the CLR works. If the environment variable is set it attaches the profiler. 

How to enable the profiler can be achieved anyway you want - powershell script, MsBuild ... depending on your build, as long as it sets the environment variables before the test runner process has started. 

If you have MsBuild on your side you can have a look at our JustMockStart and JustMockStop tasks here

Regards,
Svetlozar
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
Tags
General Discussions
Asked by
Tormod
Top achievements
Rank 2
Answers by
Chris
Telerik team
Shane Milton
Top achievements
Rank 2
Ricky
Telerik team
Mihai
Top achievements
Rank 1
Aaron Reed
Top achievements
Rank 1
Svetlozar
Telerik team
Share this question
or