Last Updated: 23 Jul 2018 13:31 by Kaloyan
Current behavior:
Mock.Arrange(xxx).IgnoreInstance();    //mock all future instances of the type on which I set an expectation.

Feature Request:
Mock.Arrange(xxx).IgnoreInstance().Next();    //mock the next instance of the type on which I set an expectation.

...and even better...

Mock.Arrange(xxx).IgnoreInstance().Skip(3).Next();   //mock the 4th instance of a type on which I set an expectation.
Last Updated: 17 May 2013 12:44 by Jakub
When I try to invoke method from intercepted class in multi-thread test sometimes I get following exception:
Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
   at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList(IEnumerable`1 source)
   at Telerik.JustMock.Weaver.ContainerContext.InstanceIdentifier.GetUniqueId(Object target)
   at Telerik.JustMock.Weaver.ContainerContext.Get(Type targetType, MethodBase methodInfo, Object target)
   at Telerik.JustMock.Weaver.ContainerContext.Get(MethodBase methodBase, Object target)
   at Telerik.JustMock.Weaver.Interceptors.WeaverInterceptor.OnInvocation(IInvocation invocation)
   at Telerik.JustMock.Weaver.Interceptors.WeaverInterceptor.Telerik.JustMock.Weaver.Interceptors.Abstraction.IWeaverInterceptor.Intercept(IInvocation invocation)
   at TestClass_Interceptor_620e5e80fe0c4d738f7ef291ea50ea2a.Intercept(TestClass, ref Boolean)
   at ExceptionExample.TestClass.ExecuteSomething() in Test.cs: line 174
   at ExceptionExample.RunMethod() in Test.cs: line 199
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Sample class that generates exception:

public class ExceptionExample
	static ExceptionExample()

	public class TestClass
		public void ExecuteSomething()
			int y = 0;
			for (int i = 0; i < 100; i++)
				y += i;

	public void MethodName()
		List<Thread> l = new List<Thread>();

		for (int i = 0; i < 6; i++)
			Thread t = new Thread(RunMethod);

		l.ForEach(th => th.Join());

	private void RunMethod()
		for (int i = 0; i < 10000; i++)
			TestClass tc1 = new TestClass();
Last Updated: 21 May 2013 13:39 by Kaloyan
Should be able to arrange against non-public methods taking ref or out arguments as parameter.
Last Updated: 17 May 2013 12:23 by Kaloyan
Created by: Kaloyan
Comments: 0
Type: Feature Request
I'd like to intercept a call to a generic method similar to:

public  class MyClass
    public void MyMethod<T>()

Now I want to arrange a MyClass instance so I can assert that the method has been call only once for an specific type and never for any other type. I'm tryig to do something similar to:

var service = Mock.Create<MyClass>();
Mock.Arrange(() => service.MyMethod<T>()).OccursNever();

So I can assert the generic method is never called.
Last Updated: 17 May 2013 12:23 by David
I'm getting this argument exception:
System.ArgumentException : The type or method has 3 generic parameter(s), but 2 generic argument(s) were provided. A generic argument must be provided for each generic parameter.
   at System.RuntimeType.SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
   at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
   at .š.(Type ‹, MethodBase „†, BindingFlags )
   at .š.(Type ‚, MethodBase „†)
   at ”.“.Create(Object š, MethodInfo ›, Boolean ’)
   at ..(˜ )
   at ..(Expression`1 )
   at Telerik.JustMock.Mock..Ž( )
   at ..—[,—]( , Func`2 )
   at Telerik.JustMock.Mock.Arrange[TResult](Expression`1 expression)

Heres an example of a failing test:

        public void GenericTestCanMockTwoGenericMethods()
            var mocked = Mock.Create<GenericTest>();
            IEnumerable<EVENT_CODE> n = null;
            Mock.Arrange(() => mocked.Query<EVENT_CODE, ALARM_CODE>(Arg.AnyString, Arg.IsAny<object>())).Returns(n).MustBeCalled();

        public interface GenericTest
            IEnumerable<T1> Query<T1, T2>(string arg1, params object[] args);

            IEnumerable<T1> Query<T1, T2, T3>(string arg1, params object[] args);
Last Updated: 27 Aug 2013 06:39 by Omer
Created by: Omer
Comments: 0
Type: Bug Report
Hi there, I'm a developer on OzCode, a Visual Studio extension ( www.oz-code.com ).

We've received some complaints from customers that OzCode is incompatible with JustCode. I installed JustMock, and saw that when Visual Studio starts up, JustMock it seems to be causing a crash in a child process that OzCode spawns off of devenv.exe, which is called 'BugAidMetadataLoader.exe':

The exception in this process is:

Additional information: Could not load type 'Telerik.JustMock.Profiler' from assembly 'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

I would guess that JustMock is unintentionally causing the process to be loaded with a CLR Profiler attached and injecting code into it, and the injected code causes the crash.

Could you please provide some advice on how to avoid this, or possibly provide a fix?

Thank you very much,
 - Omer Raviv, OzCode
Last Updated: 26 Nov 2019 10:08 by ADMIN
.Net for application developers prefer writing their build script using cake. It is necessary for JustMock to have a cake utility to work with. 
Last Updated: 20 Feb 2020 07:04 by ADMIN
When I try to create a new JustMock test project for .NET Framework the version of .NET Framework that I select is not respected. The result is that the used version of .NET Framework is always 4.5.2
In Development
Last Updated: 19 Feb 2020 08:24 by ADMIN
Last Updated: 20 Feb 2020 06:56 by ADMIN

Currently, there are a lot of JustMock project templates with different targeted categories. There are templates targeting just one search category and there are other templates targeting different categories.

Optimize the templates to be available in all relevant search categories and lower their number.

Last Updated: 20 Feb 2020 07:05 by ADMIN


According to the JustMock documentation, to validate a method on the mock was called it should be done like so:

public void ShouldThrowExceptionWhenMustBeCalledSetupIsNeverInvoked() 
    // Arrange 
    var foo = new Foo(); 

    Mock.Arrange(() => foo.Execute()).MustBeCalled(); 

    // Assert 
    Assert.Throws<AssertFailedException>(() => Mock.Assert(foo)); 

When I do that, the application fails to compile saying the type AssertFailedException does not exist, even though I have the using statement for the Telerik.JustMock assembly at the top of my file. If I try to fully qualify it like so:


I get the same message for the "Xunit" namespace.

I know that the type should exist since when I run the test asserting a different type of Exception, the test fails saying it expects an exception of type Telerik.JustMock.Xunit.AssertFailedException.

I am attaching a couple of images that illustrate the problem.

Thank you.


Last Updated: 20 Feb 2020 06:53 by ADMIN

The integration does not work as expected when the tests are run on the command line outside Visual Studio via dotnet test command. The coverage is used as Microsoft.CodeCoverage NuGet package.


Last Updated: 21 Feb 2020 11:53 by ADMIN
Created by: Toshio
Comments: 0
Type: Bug Report
An attempt to use future mocking fails. The attached sample demonstrates the issue.
Last Updated: 21 Feb 2020 11:51 by ADMIN


When enabling JUSTMOCK Profiler it stops a MS rdlc report to render.

I have attached a simple sample demonstrating the error.

The error that the render gives back is the following.

The definition of this report is not valid or supported by this version of Reporting Services. The report definition may have been created with a later version of Reporting Services, or contain content that is not well-formed or not valid based on Reporting Services schemas. Details: Deserialization failed: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) Line 2, position 2.

I have tried to different target version of the .NET framework 4.5.2; 4.6.2, different platform targets "ANY,x86,x64", different VS IDE "2012, 2015", different Microsoft.ReportViewer.WinForm  ver. 11,12,14

Last Updated: 30 May 2019 08:38 by ADMIN

Let's have the following class and unit test:

public delegate Task<int> SomeDelegate();

public class Class1
    public async Task<int> ExecuteAsync(SomeDelegate next)
        Task<int> task1 = next.Invoke();
        int int1 = await DoSomeStuff();
        int int2 = await task1;
        return int1 + int2;

    private async Task<int> DoSomeStuff()
        await Task.Delay(100);
        return 1;

public async Task TestMethod1()
    // Arrange
    SomeDelegate next = Mock.Create<SomeDelegate>();
    next.Arrange(n => n.Invoke()).TaskResult(2).OccursOnce();
    // Act
    int sum = await new Class1().ExecuteAsync(next);

    // Assert
    Assert.AreEqual(3, sum);

JustMock public API lacks of convenient way to assert that particular task has been awaited. Potential workaround involves some "insider knowledge" that awaiting a Task internally results in a calls to some of its members.

Last Updated: 02 Dec 2019 10:39 by ADMIN
Mocking a method that is not used in the test execution logic could lead to unwanted recursive mocking behavior for the rest of the methods in the class. 
The unwanted behavior could later result in an exception if the affected methods are called during the arrangement of another method.
Last Updated: 18 Jun 2019 10:06 by ADMIN

Values from already mocked methods are not taken into account when initializing a static constructor from the Telerik.JustMock.PrivateAccessor class.

Here is an example: PrivateAccessor.ForType(typeof(Foo)).SetField("someStringField", "stringvalue");

A workaround is to call the: Mock.Intercept(typeof(Foo)); before calling the PrivateAccessor.

Last Updated: 18 Jun 2019 14:21 by ADMIN
The scenario includes two async tests executed synchronously. The first test doesn't have an await task call and in some random runs fails to call Mock.Reset. This messes the mocked objects of the second async test.
Last Updated: 18 Jun 2019 08:34 by ADMIN
I have a .Net Core solution and want to see the code coverage in VS 2019. However, when I run the tests with code coverage, I get the error message, that the profiler is not enabled, although it is enabled. The test is green without code coverage (and with enabled profiler). It is also green and the coverage is displayed with JustMock commented out and the profiler disabled.
Last Updated: 24 Sep 2019 10:08 by ADMIN
Elevated unit testing does not work with NET Core SDK 3.0.100 - preview8