Support,
I am attempting to use JustMock to mock ServiceSecurityContext based on this article here.
If I am understanding this Telerik article, I should be able to use the NuGet package and configure a profiler using a ".runsettings" file without needing to install the configuration tool.
Here is the .runsettings file I have added to my test project:
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<JUSTMOCK_INSTANCE>1</JUSTMOCK_INSTANCE>
<CORECLR_ENABLE_PROFILING>1</CORECLR_ENABLE_PROFILING>
<CORECLR_PROFILER>{B7ABE522-A68F-44F2-925B-81E7488E9EC0}</CORECLR_PROFILER>
<CORECLR_PROFILER_PATH>..\packages\justmock.commercial\2024.2.514.325\runtimes\win-x64\native\Telerik.CodeWeaver.Profiler.dll</CORECLR_PROFILER_PATH>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
Unfortunately, this did not work and I am still getting the following error when running my tests.
Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'System.ServiceModel.ServiceSecurityContext'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* {865fc36f-7fab-44b6-bbb7-c2baea8d9ad2} (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.
What am I missing to get this configured?
Thanks,
-Scott
1 Answer, 1 is accepted
Hello Scott,
It seems you are using a third-party profiler along with JustMock, which is more likely code coverage. Please confirm since the proper setup requires a bit of a different approach. One more detail, the file path in the runsettings is a relative one, make sure that it is the right one referred to the test runner working directory, usually an output directory from the build.
Regards,
Ivo
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Ivo,
Could the third party profiler be ReSharper? We do use dotCover and the ReSharper test runner to get code coverage. However, this wouldn't be running on our build servers.
The relative path was to the Telerik.CodeWeaver.Profiler.dll file that was downloaded to the Packages folder by NuGet. I do see that same DLL in the bin folder, should that .runsettings file be updated as follows?
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<JUSTMOCK_INSTANCE>1</JUSTMOCK_INSTANCE>
<CORECLR_ENABLE_PROFILING>1</CORECLR_ENABLE_PROFILING>
<CORECLR_PROFILER>{B7ABE522-A68F-44F2-925B-81E7488E9EC0}</CORECLR_PROFILER>
<CORECLR_PROFILER_PATH>.\bin\debug\Telerik.CodeWeaver.Profiler.dll</CORECLR_PROFILER_PATH>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
I tried this but I'm still getting the same error.
Thanks,
- Scott
Ivo,
After a bunch of experimenting I was able to get a successful test using the .runsettings file below.
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<JUSTMOCK_INSTANCE>1</JUSTMOCK_INSTANCE>
<CORECLR_ENABLE_PROFILING>1</CORECLR_ENABLE_PROFILING>
<CORECLR_PROFILER>{B7ABE522-A68F-44F2-925B-81E7488E9EC0}</CORECLR_PROFILER>
<CORECLR_PROFILER_PATH>.\bin\Debug\Telerik.CodeWeaver.Profiler.dll</CORECLR_PROFILER_PATH>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
However, I'm only able to get a successful run if I simply run the test. If I attempt to run the test to check coverage, I get the same error as before. Additionally, the GUID mentioned in the error does not seem consistent and changes with every run.
Test method FARED_Util.Service.Test.DataServiceTest.Locality_AddVanityCity_Test threw exception: Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'System.ServiceModel.OperationContext'. The profiler must be enabled to mock, arrange or execute the specified target. Detected active third-party profilers: * {48311e8b-dd4a-4b9e-a463-1d41a86a1a24} (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 also tried this on our build server, even with the JustMock Configuration tool installed and a profiler enabled, I get a similar error as above.
Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'System.ServiceModel.OperationContext'. The profiler must be enabled to mock, arrange or execute the specified target.
This is not the ideal setup though, I would prefer to not have to install JustMock on servers in order for things to work. Additionally, other developers on my team will need to to work without having to configure their own machines for it to work.
In addition to resolving the above issues, is it possible to specify multiple profilers? Developer machines are configured differently than build machines, so I assume the .runsettings file will need to be changed depending on the environment running the test. Both types of environments will need to be supported.
Thanks,
- Scott
Hello Scott,
I am happy to hear that you can run tests using runsettings, the next step is to enable transparent integration with dotCover and run them with coverage enabled. I would like to warn you that currently, JustMock supports integration via registry on Windows only. In the upcoming Q3 release, we will add the unified approach (via config file) that can be used on all supported platforms. Please find attached minimal sample that shows how to run the tests with coverage.
Ivo,
The application you provided produces the same error and I'm unable to run the test method. Please advise.
When is the Q3 release and will that update be covered under my current license?
Test method MyClassLibrary.Test.UnitTest1.TestMethod1 threw exception:
Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'MyClassLibrary.Class1'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* {e7f16e23-5f5b-4c99-a474-b56ac1ca9c20} (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.
at Telerik.JustMock.Core.ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member)
at Telerik.JustMock.Core.MocksRepository.InterceptStatics(Type type, MockCreationSettings settings, Boolean mockStaticConstructor)
at Telerik.JustMock.Core.CallPatternCreator.FromExpression(MocksRepository repository, Expression expr)
at Telerik.JustMock.Core.MocksRepository.Arrange[TMethodMock](Expression expression, Func`1 methodMockFactory)
at Telerik.JustMock.Mock.<>c__DisplayClass4_0.<Arrange>b__0()
at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
at Telerik.JustMock.Mock.Arrange(Expression`1 expression)
at MyClassLibrary.Test.UnitTest1.TestMethod1() in C:\SRC\mysolution\MyClassLibrary.Test\UnitTest1.cs:line 13
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
- Scott
Hello Scott,
I assume you have used a batch script to run the sample; if not, please use it since it sets things up correctly; if so, then I would like to ask you to insert a few lines just before launching the test runner (at run-tests-with-dotcover.bat:36), here there are:
set JUSTMOCK_LOG_LEVEL=DEBUG set JUSTMOCK_LOG_FILE_PATH=[Provide a full path to the log file, must be placed in the existing diretory]
Re-run the batch and send us a log file for analysis.
Regarding 2024.Q3 release, it is expected to be available in mid-September and your current license will allow you to upgrade.
Ivo,
No, I am not using a batch script to run the sample. I simply just opened it in Visual Studio 2022, compiled the solution and ran the test. This would be the preferred way to run this, not a batch script. Is it not possible to get this working within Visual Studio without extra steps outside of Visual Studio, such as the need to edit the registry or run the test from a batch script?
With regards to the script, I edited run-tests-with-dotcover.bat as you requested.
However, when I try to run it, I just get the following error despite having my credentials in the nuget.config file you provided.
Please setup credentials for accessing Telerik NuGet feed (look at nuget.config file in the solution directory), exiting now.
I tried just commenting out that section of the run-tests-with-dotcover.bat script, but that just produced a bunch of 401 errors when trying to install something called "JetBrains.dotCover.GlobalTool" and "dotnet-reportgenerator-globaltool". This was especially a surprise since I wasn't expecting anything to be installed and you did not provide any documentation to support this project.
I've attached the output I received for your review but I was not able to get this to produce a log file.
Thanks,
- Scott
Scott,
At this point, it would be easier to have a short live session and try to resolve the issue together. Please register a support ticket so we can communicate the details privately. Thank you!
I am getting same error. Did we get any solution for this?
I am using following
Visual Studio 2022
JustMock 2024.2.514.325
Resharper / dotCover 2024.2.6
@Varshil,
No, ultimately, I ended up rearchitecting the project and finding a different solution using Moq. Below is the last post to the support ticket that was created. Telerik support never responded further.
-----------------
After a bunch of experimenting, I was able to get a successful test using the .runsettings file below.
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<JUSTMOCK_INSTANCE>1</JUSTMOCK_INSTANCE>
<CORECLR_ENABLE_PROFILING>1</CORECLR_ENABLE_PROFILING>
<CORECLR_PROFILER>{B7ABE522-A68F-44F2-925B-81E7488E9EC0}</CORECLR_PROFILER>
<CORECLR_PROFILER_PATH>.\bin\Debug\Telerik.CodeWeaver.Profiler.dll</CORECLR_PROFILER_PATH>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
However, I'm only able to get a successful run if I simply run the test. If I attempt to run the test to check coverage, I get the same error as before. Additionally, the GUID mentioned in the error does not seem consistent and changes with every run.
Test method [REDACTED] threw exception: Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'System.ServiceModel.OperationContext'. The profiler must be enabled to mock, arrange or execute the specified target. Detected active third-party profilers: * {48311e8b-dd4a-4b9e-a463-1d41a86a1a24} (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 also tried this on our build server, even with the JustMock Configuration tool installed and a profiler enabled, I get a similar error as above.
Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'System.ServiceModel.OperationContext'. The profiler must be enabled to mock, arrange or execute the specified target.
This is not the ideal setup though; I would prefer to not have to install JustMock on servers in order for things to work. Additionally, other developers on my team will need to work without having to configure their own machines for it to work.
In addition to resolving the above issues, is it possible to specify multiple profilers? Developer machines are configured differently than build machines, so I assume the .runsettings file will need to be changed depending on the environment running the test. Both types of environments will need to be supported.
Thanks,
-Scott