Telerik Forums
JustMock Forum
1 answer
13 views

We've started seeing the above error on our build server.  It seems to have appeared out of nowhere.

xUnit.net Console Runner v2.4.1 (64-bit Desktop .NET 4.7.2, runtime: 4.0.30319.42000)
      Discovering: IRONSolutions.Core.Tests
      Discovered:  IRONSolutions.Core.Tests
      Starting:    IRONSolutions.Core.Tests
        [FATAL ERROR] System.ArgumentException
          System.ArgumentException : 'this' type cannot be an interface itself.
          Stack Trace:
               at System.RuntimeTypeHandle.VerifyInterfaceIsImplemented(RuntimeTypeHandle handle, RuntimeTypeHandle interfaceHandle)
               at System.RuntimeTypeHandle.VerifyInterfaceIsImplemented(RuntimeTypeHandle interfaceHandle)
               at System.RuntimeType.GetInterfaceMap(Type ifaceType)
               at Telerik.JustMock.Core.MockingUtil.IsImplementedBy(MethodInfo interfaceMethod, MethodBase implMethod)
               at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.MatchTestClassDispose(MethodBase method, String[] testMethodAttributes)
               at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
               at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
               at System.Linq.Enumerable.<DistinctIterator>d__64`1.MoveNext()
               at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
               at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
               at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.GetTestMethod()
               at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.FindTestMethod(Int32& repoIdx, RepositoryOperationsBase& entryOps)
               at Telerik.JustMock.Core.Context.HierarchicalTestFrameworkContextResolver.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
               at Telerik.JustMock.Core.Context.MockingContext.ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior)
               at Telerik.JustMock.Core.MocksRepository.GetMockMixin(Object obj, Type objType)
               at Telerik.JustMock.Core.Invocation..ctor(Object instance, MethodBase method, Object[] args)
               at Telerik.JustMock.Core.ProfilerInterceptor.InterceptCall(RuntimeTypeHandle typeHandle, RuntimeMethodHandle methodHandle, Object[] data)
               at System.Environment.get_NewLine()
               at System.Exception.PrepForRemoting()
               at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
               at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
        [FATAL ERROR] System.ArgumentException
          System.ArgumentException : 'this' type cannot be an interface itself.


Has anyone seen this error before and know of a fix?  Any help would be greatly appreciated.  We're using JustMock_2023_1_117_1_Dev.

Martin
Telerik team
 answered on 01 May 2024
2 answers
231 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
377 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
203 views

I'm working on tests for legacy code that instantiates a ServiceController (in System.ServiceProcess) to check for a running SQL Server instance. I want to add the tests to our CI/CD build pipeline, so I decided to use JustMock to future-mock ServiceController since the service in question will not exist on the build server. These tests are all using xUnit.

However, the test (which has 3 variants specified via xUnit's InlineData attributes) started hanging on the first variant. It's not just long-running; I've let it run for hours (it's normally a 3-second test at most), and CPU usage is negligible. ServiceController is IDisposable, so I figured it might have something to do with that.

After a lot of paring down, I can repro the problem with the following code in a new project:

public class JustMockTest
{
    [Theory]
    [InlineData("test")]
    public void TestMethod(string whatever)
    {
        Mock.Arrange(() => new ServiceController()).DoNothing();
    }
}

However, this test (in the same class) works fine and completes in about 1s - note that it's a fact, not a theory:

[Fact]
public void TestMethod2()
{
    Mock.Arrange(() => new ServiceController()).DoNothing();
}

This is JustMock v2022.1.223.1, xUnit v2.4.1.0, and VS 2022.

At first I wondered if my 3 variants were somehow stepping on each other's Mock.Arrange() statements; but as you can see, the top test, while declared as a theory, only has 1 variant and still has the problem. What's also interesting is that an analogous setup for MSTest also runs fine - so this seems to be xUnit-specific somehow:

[TestClass]
public class UnitTest1
{
    [DataTestMethod]
    [DataRow("test")]
    [DataRow("test2")]
    public void TestMethod1(string whatever)
    {
        Mock.Arrange(() => new ServiceController()).DoNothing();
    }
}

At first I thought IDisposable classes may be the problem, but it seems it's actually MarshalByRefObject; it's a base class of ServiceController and others I can repro with (WebClient, MemoryStream, etc.), and I can also repro by mocking a simple class of my own that extends MarshalByRefObject.

Is this a known issue? Are there recommended workarounds (without having to ditch xUnit for MSTest or another framework)?

Thanks!
Jeremy

Ivo
Telerik team
 answered on 06 Jul 2022
1 answer
964 views

Hi,

I'm trying to create a pipeline on Azure for test/coverage using JustMock, my application is Core 5.0*

After a long journey to make the build work, now I'm encountering an issue with the test (JustMockVSTestV2)


steps:
- task: vs-publisher-443.jm-vstest-2.JustMockVSTest-2.JustMockVSTest@2
  displayName: 'VsTest - testAssemblies'
  inputs:
    testAssemblyVer2: |
     **\bin\**\*test*.dll
     !**\*TestAdapter.dll
     !**\*TestPlatform*
     !**\obj\**
     !**\bin\**\ref\**

    pathTo64BitJustMockProfiler: '[correctpath]\bin\Release\net5.0\runtimes\win-x64\native\Telerik.CodeWeaver.Profiler.dll'
    pathTo32BitJustMockProfiler: '[correctpath]\bin\Release\net5.0\runtimes\win-x86\native\Telerik.CodeWeaver.Profiler.dll'
    vsTestVersion: toolsInstaller
    runTestsInIsolation: true
    codeCoverageEnabled: true
    otherConsoleOptions: '/Framework:.NETCoreApp,Version=v5.0.401 /Enablecodecoverage /logger:trx'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

 

My Test functions requires elevation:


Mock.SetupStatic(typeof(AStaticClass));

var response = Mock.Create<IRestResponse<string>>(); //this is restsharp
            Mock.Arrange(() => response.Data)
                .Returns("SomeData");

var client = Mock.Create<RestClient>(Constructor.Mocked);
            Mock.Arrange(() => client.ExecuteAsync<string>(Arg.IsAny<IRestRequest>(), Arg.IsAny<CancellationToken>()))
                .IgnoreInstance()
                .TaskResult(response);

 

My test project works fine on my local machine when I enable JustMock profile, however I get a bunch of errors on Azure pipeline:


##[error][xUnit.net 00:00:03.76]     ProjectTests.GetAsync_StateUnderTest_ExpectedBehavior [FAIL]
[xUnit.net 00:00:03.76]       System.InvalidProgramException : Common Language Runtime detected an invalid program.
[xUnit.net 00:00:03.76]       Stack Trace:
[xUnit.net 00:00:03.79]            at ProjectTests.GetAsync_StateUnderTest_ExpectedBehavior()
[xUnit.net 00:00:03.79]            at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
[xUnit.net 00:00:03.79]            at ProjectTests.GetAsync_StateUnderTest_ExpectedBehavior()

ALSO

##[error]Testhost process exited with error: Cannot use file stream for [PATH\bin\Release\net5.0\testhost.deps.json]: No such file or directory
##[error]A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\hostedtoolcache\windows\dotnet'.
##[error]Failed to run as a self-contained app.
##[error]  - The application was run as a self-contained app because 'PATH\bin\Release\net5.0\testhost.runtimeconfig.json' was not found.
##[error]  - If this should be a framework-dependent app, add the 'PATH\bin\Release\net5.0\testhost.runtimeconfig.json' file and specify the appropriate framework.
##[error]. Please check the diagnostic logs for more information.

 

Please advice, I'm not able to make JustMock to work with Azure Pipeline.

 

Thanks

Ivo
Telerik team
 answered on 17 Sep 2021
1 answer
205 views

Over the weekend Visual Studio was upgraded to 16.10.0 on our self-hosted Azure DevOps agent server. This has caused all of our unit tests that rely on the JustMock profiler to begin failing with the Exception:

Failed {METHODNAME} [6 ms]
  Error Message:
   Test method {NAMESPACE}.{CLASSNAME}.{METHODNAME} threw exception: 
System.InvalidProgramException: Common Language Runtime detected an invalid program.
  Stack Trace:
      at {NAMESPACE}.{CLASSNAME}.{METHODNAME}()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at {NAMESPACE}.{CLASSNAME}.{METHODNAME}()

We are using JustMock R2 2021, the Telerik JustMock VSTest v.2 (v2.6.1) pipeline task, and our test projects are targeting netcore3.1.

The tests run and pass when executed locally through Visual Studio (16.10.0) Test Explorer, but fail during pipeline execution. Nothing else has changed on the agent server except for the Visual Studio upgrade that I am aware of.

Pipeline YAML:

jobBuildAndPublishWebsite_${{ parameters.jobName }}
  displayName'Build and Publish Website - ${{ parameters.jobName }}'
  steps:
    - checkoutself
      cleantrue
      fetchDepth10
    - taskDotNetCoreCLI@2
      displayName'dotnet restore'
      inputs:
        commandrestore
        projects'**/*.csproj'
        vstsFeed${{ parameters.vstsFeedId }}
    - taskDotNetCoreCLI@2
      displayName'dotnet build'
      inputs:
        projects'**/*.csproj'
        arguments'--no-restore --nologo --configuration ${{ parameters.buildConfiguration }}'
taskJustMockVSTest@2
      displayName'Run Unit Tests'
      inputs:
        testAssemblyVer2: |
          **\*tests*.dll
          **\*Tests*.dll
          !**\*TestAdapter.dll
          !**\obj\**
          !**\packages\**
        pathTo64BitJustMockProfiler'$(System.DefaultWorkingDirectory)\lib\Telerik\JustMock\CodeWeaver\64\Telerik.CodeWeaver.Profiler.dll'
        pathTo32BitJustMockProfiler'$(System.DefaultWorkingDirectory)\lib\Telerik\JustMock\CodeWeaver\32\Telerik.CodeWeaver.Profiler.dll'
        vsTestVersionlatest
        runInParalleltrue
        codeCoverageEnabledtrue

 

Mihail
Telerik team
 answered on 04 Jun 2021
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?