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.
C# 8 introduces default interface method implementations. Attempt to mock such methods with JustMock in elevated mode fails. The following example illustrates the issue:
public interface IMyInterface
{
int IntProperty { get => 0; }
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var mock = Mock.Create<IMyInterface>();
Mock.Arrange(() => mock.IntProperty).Returns(1);
Assert.AreEqual(1, mock.IntProperty);
}
}
With R3 2023 (2023.3.1011.155) JustMock introduces a new functionality that might lead to a huge performance drop and event to unexpected failures. Currently, the issue could be suppressed by setting up an environment variable JUSTMOCK_NEWOBJ_INTERCEPTION_ON_OVERWRITE_ENABLED to 0 (the default value is 1), but a more reliable and independent solution should be found.
Collection mock (result from ReturnCollection clause) does not support async queries due to the unimplemented IAsyncQueryProvider interface. The issue could be easily reproduced with the following simple test:
[Fact]
public void ShouldReturnEntity()
{
var db = Mock.Create<MyModel.MyModel>();
Mock.Arrange(() => db.SomeEntities).ReturnsCollection(someEntities);
var entity = db.SomeEntities.SingleAsync(x => x.Id == 1);
Assert.NotNull(entity);
}
The outcome is the the following exception:
System.InvalidOperationException The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider'. Only providers that implement 'IAsyncQueryProvider' can be used for Entity Framework asynchronous operations.
By default JustMock matches the mock parameters via Object.ReferenceEquals(...). It would be nice to match the mock parameters via Object.Equals(...) as well. http://www.telerik.com/community/forums/justmock/general-discussions/parameter-matching.aspx
Since JustMock Q1 2013 Mock.DoNotUseProfiler() is marked as an obsolete method and I cannot compile my test project. Revert it back.
Please allow automocking support for classes with multiple constructors. This is important for projects not using DI containers but using dependency injection. A classic example is ASP.NET MVC and ASP.NET Web API where standard routing requires a constructor with no parameters. When using DI via constructors but without containers, the overloaded ctor specifies services/repositories and the default ctor passes the default services/repositories.
"After struggling with TypeMock for an hour, I gave #JustMock a try and it works great! Thanks." https://twitter.com/JohnFecko/status/316211813761040384
Using InOrder() in the arrange sometimes may be not appropriate. I would like to be able to do this in the assert. Instead of having the following workflow: //Arrange (initial conditions) // setup expected results (ordering) // Act // Assert , I will have this: //Arrange //Act // Assert (expected results in order)
I have a unit test where I assert that a certain action will call a method on a mock dependency object by using Mock.Assert(). I want to ensure that the action I take calls the method on the mock object exactly once. The problem is that the setup of the unit test creates a scenario where the method of the mock object will also be called, so when I assert that the call to the mock object happened just once it fails because it has actually been called more than once. Is there a way to "reset" the call tracking of methods on mock objects? I basically want to tell JustMock that at a certain point, whatever calls have happened to my mock objects should be discarded and the call counter should basically start at 0 again.
Make Justmock full edition as easy to use as the lite edition. For my team to use Justmock in Visual Studio and have unit tests run in the build system outside of VS, it is not practical to have justmock "installed" on everyone's machine. the process environment variables that need to be set is also not practically due to our custom build system; the process to start VS on our dev's enlistments is complicated and tightly controlled. Also, the profiler interferes with VS Code Coverage and we shouldn't have to use another UI to add the profiler, as that has to be done on every machine. We have to resort to just using JustMock Lite.
Given: public abstract class Foo { } [Test] public void test_foo() { Mock.Create<Foo>(Behavior.Strict, Constructor.Mocked); } An exception is thrown at runtime saying "Abstract Type is not Accessible for Inheritance". This doesn't lead you to the actual problem which is that I accidentally swapped the Behavior and the Constructor in the parameter order. The same problem can occur if you attempt to call a constructor on an abstract object with the wrong number of parameters like so: public abstract class Foo { public Foo(int a, string b) { } } [Test] public void test_foo() { Mock.Create<Foo>(1, "foo", null); } This seems to be a problem with the compiler choosing the wrong overload to call and unfortunately there aren't a lot of solutions without changing the Create API. Perhaps having an alternative to Mock.Create that is more explicit that we can use to avoid typos leading to exceptions that are difficult to make sense of or a hint in the exception message that suggests what the root cause might be?
using NUnit.Framework; using Telerik.JustMock; namespace Example { public class MyClass { public MyClass(int a = 5) { } } [TestFixture] public class TestMyClass { [Test] public void test_MyClass() { Mock.Create<MyClass>(Behavior.CallOriginal); } } } Telerik.JustMock.MockException : Can not instantiate proxy of class: Example.MyClass. Could not find a parameterless constructor. at Telerik.JustMock.Core.MocksRepository.Create(Type type, MockCreationSettings settings) at Telerik.JustMock.MockBuilder.Create(MocksRepository repository, Type type, Object[] constructorArgs, Nullable`1 behavior, Type[] additionalMockedInterfaces, Nullable`1 mockConstructorCall, IEnumerable`1 additionalProxyTypeAttributes, List`1 supplementaryBehaviors, List`1 fallbackBehaviors, List`1 mixins) at Telerik.JustMock.Mock.<>c__DisplayClass5b`1.<Create>b__5a() at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction) at Telerik.JustMock.Mock.Create[T](Behavior behavior, Object[] args) at Example.TestMyClass.test_MyClass() in c:\users\micah\Documents\Source\Test\Test\Class1.cs:line 17#0 This appears to be related to the recent fix for "Improve exception message for Mock.Create". Without Behavior.CallOriginal it works. Supplying a parameter also works.