We're developing .net 5/core services, using Rider IDE and MacOS.
Please:
1. Add support to run JustMock under MacOS (profiler need to be supported, enabled issue, etc.), or if already supported, please provide instructions of how to activate it per test, for example using NUnit.
2. Add integration with Rider so all the process will be much easier.
Mock.Create<IPool>() fails with
Telerik.JustMock.Core.MockException : Abstract type 'IPool' is not accessible for inheritance.
In Telerik.JustMock.Core.MocksRepository.Create(Type type, MockCreationSettings settings)
In Telerik.JustMock.Mock.<>c__39`1.<Create>b__39_0()
In Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
when trying to create a mock object from
public interface IPool
{
object GetItem(in Struct a, out Class b);
}
Using elevated mocking mode (profiler enabled) with long path names for the test containers (above 260 characters) causes the following command:
dotnet test
to fail with error:
Testhost process exited with error: Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at Microsoft.VisualStudio.TestPlatform.TestHost.Program.Main(System.String[]) . Please check the diagnostic logs for more information. Test Run Aborted.
There are older releases with a version of 1.0.0.4 for the Telerik.JustMock.Console.exe and with the R3 2022 release, the version is 1.0.0.3.
Referencing the nuget Microsoft.ApplicationInsights.AspNetCore V2.20.0 in the project that is tested leads to the VS 2019 code coverage failing to produce the report. Here are the steps to reproduce:
1. Create a project from the template ASP.NET Core Web API targeting .NET 5
2. Add a reference to the nuget package Microsoft.ApplicationInsights.AspNetCore V2.20.0
3. Create a unit test project from the C# JustMock Test Project (.NET Core) template.
4. Run the VS code coverage.
Expected result: the code coverage report is produced.
Actual result: there is no code coverage report
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.
Using the mentioned (or later) product version, the following simple test fails (throws NullReferenceException):
[TestMethod]
public void TestMethod()
{
var cultureInfo = Mock.Create<CultureInfo>();
var thisThrowsAnException = cultureInfo.Name;
}
One of the possible workarounds is to create a mock like this:
readonly string cultureName = CultureInfo.InvariantCulture.Name;
...
var cultureInfo = Mock.Create(() => new CultureInfo(cultureName));
Using a different version of the NuGet package compared to the locally installed product could cause an unexpected error to occur, see the screenshot below:
The case is reproducible (but might not be limited to) in a dedicated environment including Windows 10, JustMock R3.2021, Visual Studio 2019 and .NET 5. When the profiler is enabled the Visual Studio has problems with the test discovery and reports "Stack overflow" exception. The same applies to building solutions with Azure Function project.
CLR Stack from memory dump captured upon test execution:
000000CD7CE038D0 00007ffafb22d3b6 [GCFrame: 000000cd7ce038d0] 000000CD7CE03A40 00007ffafb22d3b6 [GCFrame: 000000cd7ce03a40] 000000CD7CE0A530 00007ffafb22d3b6 [PrestubMethodFrame: 000000cd7ce0a530] System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(System.Reflection.RuntimeAssembly, System.String) 000000CD7CE0A988 00007ffafb22d3b6 [GCFrame: 000000cd7ce0a988] 000000CD7CE0E3C0 00007ffafb22d3b6 [PrestubMethodFrame: 000000cd7ce0e3c0] System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(System.Reflection.RuntimeAssembly, System.String) ... (omitted for brevity) 000000CD7CF72548 00007ffafb22d3b6 [GCFrame: 000000cd7cf72548] 000000CD7CF75F80 00007ffafb22d3b6 [PrestubMethodFrame: 000000cd7cf75f80] System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(System.Reflection.RuntimeAssembly, System.String) 000000CD7CF763D8 00007ffafb22d3b6 [GCFrame: 000000cd7cf763d8] 000000CD7CF79E10 00007ffafb22d3b6 [PrestubMethodFrame: 000000cd7cf79e10] System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(System.Reflection.RuntimeAssembly, System.String) 000000CD7CF7A268 00007ffafb22d3b6 [GCFrame: 000000cd7cf7a268] 000000CD7CF7DCA0 00007ffafb22d3b6 [PrestubMethodFrame: 000000cd7cf7dca0] System.Collections.Generic.Dictionary`2[[System.__Canon, System.Private.CoreLib],[System.__Canon, System.Private.CoreLib]]..ctor() 000000CD7CF7DF10 00007FFA9B787B2A System.AppContext..cctor() [/_/src/System.Private.CoreLib/shared/System/AppContext.cs @ 16] 000000CD7CF7E340 00007ffafb2b6c93 [GCFrame: 000000cd7cf7e340] 000000CD7CF7ED18 00007ffafb2b6c93 [HelperMethodFrame: 000000cd7cf7ed18] 000000CD7CF7EE20 00007FFA9B7876B9 System.AppContext.Setup(Char**, Char**, Int32)
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);
}
}
Considering the following simple scenario:
public class Class1
{
private string arg1;
public Class1(string arg1)
{
this.arg1 = arg1;
}
public Class3 Method(string arg)
{
throw new NotImplementedException();
}
}
public class Class2
{
static Class3 class3Instance;
public static void StaticMethod(string arg1, string arg2)
{
Class1 class1Instance = new Class1(arg1);
class3Instance = class1Instance.Method(arg2);
}
}
public class Class3
{
}
[TestClass]
public class Class2Test
{
static Class1 mockClass1 = Mock.Create<Class1>();
Class3 mockClass3 = Mock.Create<Class3>();
[TestInitialize]
public void SetUp()
{
Mock.Arrange(() => new Class1("arg1")).Returns(mockClass1);
Mock.Arrange(() => mockClass1.Method("arg2")).Returns(mockClass3);
}
[TestMethod]
public void TestB()
{
Class2.StaticMethod("arg1", "arg2");
}
}
The test passes, but the debug trace output contains the warning message: "Calling one test method from another could result in unexpected behavior and must be avoided. Extract common mocking logic to a non-test method." even there is no call to the other test methods.
Currently, when the JustMock profiler is enabled it provides a performance hit on the test execution. This effect is expected because a profiler is involved.
What we can do is find a more optimized way of instrumenting the methods.