Attempt to use JustMock VSTest v.2 task to run the elevated mode tests with coverage when the "Test platform version" option is set to value "Installed by Tools Installer" fails with error:
Telerik.JustMock.Core.ElevatedMockingException: Cannot mock '<target type goes here>'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* {9317ae81-bcd8-47b7-aaa1-a28062e41c71} (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.
Having the following COM interop class
[ClassInterface(ClassInterfaceType.None)]
[Guid("86332C4E-0BDE-46EC-94C5-0A946C33C682")]
[TypeLibType(TypeLibTypeFlags.FCanCreate)]
public class MyComObjectClass : IMyComObject, MyComObject
{
public MyComObjectClass();
[DispId(1)]
public virtual string Echo(string message);
}
and the sample class that uses it:
public class MyComObjectClassProxy
{
public string Echo(string message)
{
IMyComObject itf = null;
try
{
itf = new MyComObjectClass();
return itf.Echo(message);
}
finally
{
if (itf != null)
{
Marshal.ReleaseComObject(itf);
}
}
}
}
When I try to call the arranged constructor I am getting an error "Cannot create instances of type requiring managed activation", the unit test code:
[TestMethod]
public void TestMethod1()
{
var mock = Mock.Create<MyComObjectClass>();
Mock.Arrange(() => new MyComObjectClass()).Returns(mock);
var sut = new MyComObjectClassProxy();
var actual = sut.Echo("Message");
Assert.AreEqual(string.Empty, actual);
}
I have a class, which has a private async method, which has a local function, like the following example
internal class TestClass
{
......
private async Task<bool> TestPrivateMethod()
{
var x = await TestLocalFunction();
return x;
async Task<bool> TestLocalFunction()
{
await Task.Delay(5);
return true;
}
}
When I try to mock the local function, thows an error "System.MissingMemberException : C# 7 local function 'TestLocalFunction' with the given signature was not found inside method 'TestPrivateMethod'"
var testClassInstance = Mock.Create<TestClass>(Behavior.CallOriginal);
Mock.Local.Function.Arrange<Task<bool>>(testClassInstance, "TestPrivateMethod", "TestLocalFunction").Returns(Task.FromResult(true));
Thread leak in JustMock
I am a member of the Visual Studio Perf Reliability team
Recently, I’ve found several customer dumps with huge # of threads.
In this dump:
Watson : Cab Search (microsoft.com)
Thd_ThreadStack_telerik_justmock_debugwindow_service_client!Telerik.JustMock.DebugWindow.Service.Client.ConnectionSetupServiceClientBase`[[System.__Canon,mscorlib]].get_ServiceAvailable
2,136,997,888
Progress® Telerik® JustMock Feedback Portal
There are 2084 threads using 2G mem, most with the stack below:
This is caused by threadpool starvation: the JustMock call ties up a thread for more than 1 second, then another request comes in.
The CLR will create an additional thread after 1 second to satisfy the request. This keeps happening and creates thousands of threads, each with size 1Meg.
00 ntdll!NtWaitForMultipleObjects
01 KERNELBASE!WaitForMultipleObjectsEx
02 clr!WaitForMultipleObjectsEx_SO_TOLERANT
03 clr!Thread::DoAppropriateAptStateWait
04 clr!Thread::DoAppropriateWaitWorker
05 clr!Thread::DoAppropriateWait
06 clr!SOIntolerantTransitionHandler::SetNoException
07 clr!CLREventBase::WaitEx
08 clr!CLREventBase::Wait
09 clr!AwareLock::EnterEpilogHelper
0a clr!ThreadDebugBlockingInfo::PopBlockingItem
0b clr!DebugBlockingItemHolder::{dtor}
0c clr!AwareLock::EnterEpilog
0d clr!AwareLock::Enter
0e clr!AwareLock::Contention
0f clr!JITutil_MonReliableContention
10 Telerik_JustMock_DebugWindow_Service_Client!Telerik.JustMock.DebugWindow.Service.Client.ConnectionSetupServiceClientBase<Telerik.JustMock.DebugWindow.Service.Proxy.TraceEventsSubscriptionServiceProxy>.get_ServiceAvailable
11 Telerik_JustMock_DebugWindow_Service_Client!Telerik.JustMock.DebugWindow.Service.Client.SessionServiceClientBase<Telerik.JustMock.DebugWindow.Service.Proxy.MockRepositorySubscriptionServiceProxy>.KeepAliveTimer_Elapsed
12 System_ni!System.Timers.Timer.MyTimerCallback
13 mscorlib_ni!System.Threading.TimerQueueTimer.CallCallbackInContext
14 mscorlib_ni!System.Threading.ExecutionContext.RunInternal
15 mscorlib_ni!System.Threading.ExecutionContext.Run
16 mscorlib_ni!System.Threading.TimerQueueTimer.CallCallback
17 mscorlib_ni!System.Threading.TimerQueueTimer.Fire
18 mscorlib_ni!System.Threading.TimerQueue.FireNextTimers
19 mscorlib_ni!System.Threading.TimerQueue.AppDomainTimerCallback
1a clr!CallDescrWorkerInternal
1b clr!CallDescrWorkerWithHandler
1c clr!MethodDescCallSite::CallTargetWorker
1d clr!MethodDescCallSite::Call
1e clr!AppDomainTimerCallback_Worker
1f clr!ManagedThreadBase_DispatchInner
20 clr!ManagedThreadBase_DispatchMiddle::__l16::Cleanup::{dtor}
21 clr!ManagedThreadBase_DispatchMiddle
22 clr!ManagedThreadBase_DispatchOuter
23 clr!ManagedThreadBase_FullTransitionWithAD
24 clr!ManagedThreadBase::ThreadPool
25 clr!AppDomainTimerCallback
26 clr!ThreadpoolMgr::AsyncTimerCallbackCompletion
27 clr!UnManagedPerAppDomainTPCount::DispatchWorkItem
28 clr!ThreadpoolMgr::ExecuteWorkRequest
29 clr!ThreadpoolMgr::WorkerThreadStart
2a clr!Thread::intermediateThreadProc
2b kernel32!BaseThreadInitThunk
2c ntdll!__RtlUserThreadStart
2d ntdll!_RtlUserThreadStart
when using JustMock Free in a net 5.0 app. I am getting an Ninject exception that IAssemblyNameRetriever could not be found. Looking at the code on github,
the NETCORE compile constant removes the line
AddComponent<IAssemblyNameRetriever, AssemblyNameRetriever>();
from StandardKernel.cs
however, CompiledModuleLoaderPlugin uses IAssemblyNameRetriever in it's constructor and
AddComponent<IModuleLoaderPlugin, CompiledModuleLoaderPlugin>();
is still included in the NETCORE version.
I have logging class which are using everywhere. I want to Mock this class for all tests. And i tried to use AssemblyInitialize but got problem. I have simulated this problem with JustMock.ElevatedExamples.AdvancedUsage examples: 1) Add BaseTest class [TestClass] public class BaseTest { [AssemblyInitialize()] public static void AssemblyInit(TestContext context) { Mock.SetupStatic(typeof(Common1), StaticConstructor.Mocked); // Arranging: When the static(Foo.FooProp_GET) property is called, it should return expected. var fakeUsed = Mock.Create<LogWriter1>(Constructor.Mocked); Mock.Arrange(() => Common1.Log).Returns(fakeUsed); } [AssemblyCleanup] public static void Cleanup() { //clean up stuff here } } public static class Common1 { static Common1() { Log = new LogWriter1(); } public static LogWriter1 Log { get; set; } } public class LogWriter1 { } 2) When run test from VS - all ok 3) When run from command line it is not working. Show Message box "Process Starts Now". SET JUSTMOCK_INSTANCE=1 SET COR_ENABLE_PROFILING=1 SET COR_PROFILER={B7ABE522-A68F-44F2-925B-81E7488E9EC0} "C:\Program Files (x86)\Telerik\JustMock\Libraries\JustMockRunner.exe" "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcontainer:"D:\test\CSExamples\JustMock.ElevatedExamples\bin\Debug\JustMock.ElevatedExamples.dll" How i can mock logger for all test? It is static public property. I use MS Test + VS 2015.
Hi Team,
The main telerik.com site is blocked in Sweden. I spoke to my VPN provider and got the exit IP address (217.64.148.92).
They said that the IP address used to be listed as an Iran IP in older GEO IP databases, which would explain why https://telerik.com is not working, even though it is from Stockholm
Can you please double check that your GEO IP database is not listing the Swedish IP address as being in Iran?
Thank you,
Markus
Update reference functionality wrongly suggests updating JustMock assembly reference and even more - detects currently referenced one as a lite version, see the screenshot below:
Integration with Visual Studio Enterprise Code Coverage does not work if the project refers Microsoft.NET.Test.Sdk package version 16.3 (and above). The test run fails with exception:
Telerik.JustMock.Core.ElevatedMockingException : Cannot mock '<type to mock goes here>'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\amd64\covrun64.dll (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.
The internal (non-public) events are not handled properly by JustMock, there is no indication for error, Raise arrangement simply does not working as expected. The following sample reproduces the issue:
namespace TestExample
{
public class ClassWithEvents
{
internal event EventHandler<EventArgs> InternalEventToTest;
}
[TestClass()]
public class EventTests
{
[TestMethod]
public void ClassWithEvents_InternalEventTest()
{
//Arrange
bool eventRaised = false;
ClassWithEvents classWithEvents = Mock.Create<ClassWithEvents>();
classWithEvents.InternalEventToTest += (object sender, EventArgs e) =>
{
eventRaised = true;
};
// Act
Mock.Raise(() => classWithEvents.InternalEventToTest += null, new EventArgs());
// Assert
Assert.IsTrue(eventRaised);
}
}
}
I am unable to debug my unit test .NET project. I keep getting several of these errors, and it is super slow as code tries to execute every line. I have rebooted and restarted VS 2019 several times, reinstalled JustMock but the error won't go away.
Visual Studio Output windows shows following repeated errors:
Exception thrown calling IDebugWindowPlugin plugin: System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.JustMock.Plugins.ObjectInfo.FromObject(Object value)When a breakpoint is added inside an async test that uses JustMock the debugger is failing to hit it.
To reproduce the issue follow the next steps:
1. Open the attached project
2. Create a breakpoint at the first arrangement in the async test method.
3. Start debugging the async test
Result: the breakpoint is not hit.
The issue is observed for both .NET Core and .NET Framework.
The test run is aborted when a .testsettings is used for executing JustMock tests. The .testsettings contains only a description.
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Local" id="15694c75-be1c-4113-9d42-2cbe1013c41c" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
</TestSettings>
It seems that the usage of the MSTest element is breaking the execution.
Workaround: As .testsettings are deprecated use .runsettings instead without MSTest element.