I am unable to mock interfaces that contain a method with an `in` parameter. When running the following code snippet, the result is an exception:
Message:
Test method Example.UnitTests.UnitTest.TestMethod threw exception:
Telerik.JustMock.Core.MockException: Abstract type 'Example.UnitTests.InParamExample' is not accessible for inheritance.
Stack Trace:
MocksRepository.Create(Type type, MockCreationSettings settings)
<>c__38`1.<Create>b__38_0()
ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
UnitTest.TestMethod() line 23
namespace Example.UnitTests
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Telerik.JustMock;
public interface ParamExample
{
void Foo(int param);
}
public interface InParamExample
{
void Foo(in int param);
}
[TestClass]
public class UnitTest
{
[TestMethod]
public void TestMethod()
{
var mockedParamExample = Mock.Create<ParamExample>();
var mockedInParamExample = Mock.Create<InParamExample>();
}
}
}
http://tv.telerik.com/watch/telerik/test-drive-your-code-with-justmock
https://stackoverflow.com/questions/5755413/typemock-vs-justmock-vs-rhinomock-moq-current-situation-in-2011?rq=1
is in a lot of webpages that point to whats good about just mock, except this link is broken, can you put in a redirect to the actual vids for just mock.
I currently use typemock, but looking for a team solution and having broken links and missing content implies product abandonment.
Where can I find the links to the current vid on just mock?
Thanks
Doug
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 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.
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.
Visual Studio debugger arrowhead pointer is messed when profiler is enabled with .Net Core 2.1, in VS2107/2019
Steps
Code Snippet
Mock.SetupStatic(typeof(ElasticOperationsHelper), Behavior.Strict, StaticConstructor.Mocked);
Mock.Arrange(() => elasticRepository.IndexDocumentInElastic<IndexDocText>(Arg.IsAny<IndexDocText>(), Arg.IsAny<string>(), null)).Returns(response);
While debugging it's found the arrowhead pointer of VS debugger is messed up and pointing to wrong line numbers. It's quite difficult to develop unit tests at this situation. Is there any resolution of this problem.
I found an article in the support page has been declined due to same problem. Is this totally dependent on "CLR" fix and .Net profiler. If so could you please provide me the Bug details of Microsoft for the same?
I would also like to know why it's necessary to have profiler enabled for scenarios like "Static Mocking", "Non virtual method mocking", "Private Mocking" etc.
Is this only happening for .Net core?
Hyland Software is evaluating this product as their Mocking framework for unit testing of all .net core projects.
If there is no solution, how can any prospective customer consider this as a good fit for their usage? If there is any workaround possible at this moment?
I just installed it onto desktop, loaded Visual Studio 2019 (Ent) and i see no visual reference or otherwise to JustMock.
Honestly If i had have spent the $$ by now i'd have uninstalled and given up.
When using Mock.CreateLike<> we've found that trying to directly mock anything lower than two layers down on a concrete class (e.g. x => x.Layer1.Layer2.Property == "test") throws a NullReferenceException unless the profiler is enabled. It wasn't clear in the exception or the documentation relating to this method that the real issue was the profiler being disabled, and only by trial and error did we find the solution.
this nuts, forcing me to answer a dialog for JustMock and JustTrace to turn off sending usage to Telerik. Very poor UX. Stop doing this.
Resharper 10 code coverage have tests failing when arrange to have JustMock to return values from methods called under test. Perhaps one tool too many manipulating .NET objects behind-the-scenes at a time?
Tests fail when run with vstest.console.exe but pass when run from VS2015. Findings: The problematic scenario includes reference to Microsoft.WindowsAzure.ServiceRuntime.dll and usage of the RoleEnvironment class. When the RoleEnvironment class is used in a test project without JustMock and runned from vstest.console the exception will be thrown as well. Here is the exact exception: System.TypeInitializationException: The type initializer for 'Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment' threw an exception. ---> System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> <CrtImplementationDetails>.ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain. ---> System.Runtime.InteropServices.COMException: Invalid operation. (Exception from HRESULT: 0x80131022) Stack Trace: at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at <CrtImplementationDetails>.GetDefaultDomain() at <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie) at <CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport* ) at <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* ) at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) --- End of inner exception stack trace --- at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) at .cctor() --- End of inner exception stack trace --- at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment() at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor() --- End of inner exception stack trace --- at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_IsAvailable() Workaround: the vstest.console.exe could be started with parameter /InIsolation, which runs the tests in an isolated process. Here is the link to the command line options: https://msdn.microsoft.com/en-us/library/jj155796.aspx
Since JustMock Q1 2013 Mock.DoNotUseProfiler() is marked as an obsolete method and I cannot compile my test project. Revert it back.