Telerik Forums
JustMock Forum
2 answers
163 views

Hi, 

I am trying to run the unit test for my .net 6 and want to see the code coverage using "Analyse Code Coverage for all Tests" in VS2022.

it successfully run all all test cases when I "run all Tests" but when I use "Analyse Code Coverage for all Tests" to run and see the code coverage, there are some test case failed throwing ThrowElevatedMockingException as below.

 Message: 
Telerik.JustMock.Core.ElevatedMockingException : Cannot mock 'System.Threading.Tasks.Task`1[System.Collections.Generic.List`1[AppHub.SingleView.AmazonFireStickPromo.Models.AccountPromoToken]] GetAccountPromoTokensAsync(System.String)'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* {324F817A-7420-4E6D-B3C1-143FBED6D855} (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.

  Stack Trace: 
ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member)
MocksRepository.CheckMethodInterceptorAvailable(IMatcher instanceMatcher, MethodBase method)
MocksRepository.AddArrange(IMethodMock methodMock)
MocksRepository.Arrange[TMethodMock](Object instance, MethodBase method, Object[] arguments, Func`1 methodMockFactory)
<>c__DisplayClass24_0`1.<Arrange>b__0()
ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
NonPublicExpectation.Arrange[TReturn](Object target, String memberName, Object[] args)
PromoCodeManagementServiceTests.GetAllEmailStatusesAsync_WithTokenFromAccount_ExpectedListEmailStatus() line 145
GenericAdapter`1.GetResult()
AsyncToSyncAdapter.Await(Func`1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
<>c__DisplayClass1_0.<Execute>b__0()
DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)

I think run all test is successful as I use specify env.runsettings in my project file (attached file). 

but the test run in  "Analyse Code Coverage for all Tests" failed in some methods.

Package I used

    <PackageReference Include="JustMock.Commercial" Version="2023.1.117.1" />

Can someone help me to fix this one ?

Thanks

Minh
Top achievements
Rank 1
Iron
 updated answer on 20 Apr 2023
2 answers
226 views

Hi there

We are trying to move our current build agents from Windows to Linux (Ubuntu 20.04) for all our dotnet6.0 applications and trying to integrate the JustMock Profiler on this machine because we depend on it in several tests.

Therefore, we followed your integration article "JustMock Integration on Linux".

We have copied the Profiler binaries to the build agent and referencing it through the environment variable:

root@8d248b92b005:/azp/Backend# printenv | grep 'CORE\|JUST'
CORECLR_PROFILER_PATH=/opt/TelerikJustMock/JustMock_2022_1_223_1_Dev/Libraries/CodeWeaver/64/libTelerik.CodeWeaver.Profiler.so
CORECLR_PROFILER={B7ABE522-A68F-44F2-925B-81E7488E9EC0}
JUSTMOCK_INSTANCE=1
CORECLR_ENABLE_PROFILING=1

The csproj definition for referencing the JustMock library looks (at the moment) like the following:

...
<ItemGroup>
    <Reference Include="Telerik.JustMock">
        <HintPath Condition="Exists('C:\Program Files (x86)\Progress\Telerik JustMock\Libraries\netcoreapp2.0\Telerik.JustMock.dll')">C:\Program Files (x86)\Progress\Telerik JustMock\Libraries\netcoreapp2.0\Telerik.JustMock.dll</HintPath>
        <HintPath Condition="Exists('/opt/TelerikJustMock/JustMock_2022_1_223_1_Dev/Libraries/netcoreapp2.0/Telerik.JustMock.dll')">/opt/TelerikJustMock/JustMock_2022_1_223_1_Dev/Libraries/netcoreapp2.0/Telerik.JustMock.dll</HintPath>
        <Private>True</Private>
    </Reference>
</ItemGroup>
...

In the tests we are calling the following method to check for the Profiler to be enabled:

public class Test_JustMockProfiler_Enabled
{
	[Fact]
	public void ProfilerMustBeEnabled()
	{
		Mock.IsProfilerEnabled.Should().BeTrue();
	}
}

Then running the tests with the 'dotnet test' command:

dotnet test /path/to/Tests.dll --no-build --no-restore -l:trx --results-directory ./TestResults/

But still we get the following error:

Error Message:
   Expected Mock.IsProfilerEnabled to be true, but found False.

Installed dotnet:

root@8d248b92b005:/azp/Backend# dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.402
 Commit:    6862418796

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.402/

global.json file:
  Not found

Host:
  Version:      6.0.10
  Architecture: x64
  Commit:       5a400c212a

.NET SDKs installed:
  6.0.402 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

 

Is there anything we are missing or doing wrong? 
How do we properly enable the Profile on Linux to run in 'dotnet test'?

Thanks for your help in advance, cheers.

Sandro
Top achievements
Rank 1
Iron
 updated answer on 13 Jan 2023
1 answer
366 views

Hi there

We are facing an issue on our on-premise Azure DevOps build agents, where we have JustMock installed, since the version 2.0.13 from last Thursday 6th Oct. 2022 but also with the today's version 2.0.14.

Exception:

[xUnit.net 00:00:02.79]       Telerik.JustMock.Core.ElevatedMockingException : Cannot mock 'System.DateTime'. The profiler must be enabled to mock, arrange or execute the specified target.
[xUnit.net 00:00:02.79]       Stack Trace:
[xUnit.net 00:00:02.79]            at Telerik.JustMock.Core.ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member)
[xUnit.net 00:00:02.79]            at Telerik.JustMock.Core.MocksRepository.InterceptStatics(Type type, MockCreationSettings settings, Boolean mockStaticConstructor)
[xUnit.net 00:00:02.79]            at Telerik.JustMock.Core.CallPatternCreator.FromExpression(MocksRepository repository, Expression expr)
[xUnit.net 00:00:02.79]            at Telerik.JustMock.Core.MocksRepository.Arrange[TMethodMock](Expression expression, Func`1 methodMockFactory)
[xUnit.net 00:00:02.79]            at Telerik.JustMock.Mock.<>c__DisplayClass1_0`1.<Arrange>b__0()
[xUnit.net 00:00:02.79]            at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
[xUnit.net 00:00:02.79]            at Telerik.JustMock.Mock.Arrange[TResult](Expression`1 expression)

We are using the task JustMockVSTest@2 and have no additional configurations for the JustMock Profiler set, like described in your integration guide: https://docs.telerik.com/devtools/justmock/integration/continuous-integration/tfs-azure/azure-devops

On the system there is the Profiler installed under "C:\Program Files (x86)\Progress\Telerik JustMock\Libraries\CodeWeaver\<bitness>\Telerik.CodeWeaver.Profiler.dll"

We see that the task is initializing the path to the Profiler (32bit and 64bit) to the $(System.DefaultWorkingDirectory) like:

Starting: VsTest - testAssemblies
==============================================================================
Task         : Telerik JustMock VSTest v.2
Description  : Use VSTest runner to run tests that are mocked with Telerik JustMock.
Version      : 2.7.1
Author       : Telerik
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/vstest
==============================================================================
SystemVssConnection exists true
Setting up JustMock
======================================================
The specified path to 32 bit JustMock profiler is: D:\azagent\<organisation>\A1\_work\<build>\s
The specified path to 64 bit JustMock profiler is: D:\azagent\<organisation>\A1\_work\<build>\s
SystemVssConnection exists true
Running tests using vstest.console.exe runner.
======================================================

Before the Profiler was initialized with null:

Starting: VsTest - testAssemblies
==============================================================================
Task         : Telerik JustMock VSTest v.2
Description  : Use VSTest runner to run tests that are mocked with Telerik JustMock.
Version      : 2.6.1
Author       : Telerik
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/vstest
==============================================================================
SystemVssConnection exists true
SystemVssConnection exists true
Setting up JustMock
======================================================
The specified path to 32 bit JustMock profiler is: null
The specified path to 64 bit JustMock profiler is: null
SystemVssConnection exists true
Running tests using vstest.console.exe runner.
======================================================

Is there anything we have to configure, like the absolute/relative path to the Profiler? Or is this a bug within the new release?

Thanks for your help.

Cheers

 
Ivo
Telerik team
 answered on 11 Oct 2022
1 answer
345 views

In Visual Studio 2022, the first quick action is often "Create Mock". As this is used in the overlay when hovering over a method, I see "JMA001" quite often, which is not helpful when writing non-test code.

I know that I could create a .editorconfig file to suppress individual hints for every project I work on, but how can I prevent the JustMock hints from being used in the quick actions completely across projects?

Ivo
Telerik team
 answered on 12 Aug 2022
2 answers
357 views

Hi,

I am trying to run to  Dotnet Test command for .NetCore dll in Azure Devops and It throws exception for some tests saying elevated Mocking Exception.

 

Comand Used is

taskDotNetCoreCLI@2
  displayNamedotnet test - Unit Tests
  inputs:
    commandtest
    projects'**/*.UnitTest.csproj'
    arguments--no-build --configuration $(BuildConfiguration) --logger trx --collect "Code coverage" /p:CollectCoverage=true /p:Threshold=0 /p:ThresholdType=line /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage /p:ExcludeByAttribute="DebuggerNonUserCodeAttribute" /p:ExcludeByFile=\"**/obj/**/*.cs"
    testRunTitleUnit Tests
Yanrafo
Top achievements
Rank 1
Iron
 answered on 06 Jul 2022
1 answer
1.1K+ views

Hi Team

We tried executing justMock test cases in command prompt using justMock Console (licensed), dotCover and xUnit, but justMock Test execution failed and gave the error "System.InvalidProgramException : Common Language Runtime detected an invalid program." 

The command we use to execute is as follows:

start /wait "" "{PATH}\JustMock\Libraries\Telerik.JustMock.Configuration.exe" /link "dotCover"

"{PATH}\JustMock\Libraries\Telerik.JustMock.Console.exe" runadvanced --profiler-path-64 "{PATH}\JustMock\Libraries\CodeWeaver\64\Telerik.CodeWeaver.Profiler.dll" --command "{PATH}\JetBrains.dotCover.CommandLineTools.2021.1.3\dotCover.exe" --command-args "cover --reporttype=html --output=CodeCoverage\\index.html --targetexecutable=\"{PATH}\xunit.runner.console.2.4.1\tools\net472\xunit.console.exe\" -- \"{PATH}\{PATH_OF_JUSTMOCK_TEST_DLL}\""

start /wait "" "{PATH}\JustMock\Libraries\Telerik.JustMock.Configuration.exe" /unlink "dotCover"

 

Attaching the log and test code.

Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?