Hi there, I'm trying to profile a very slow unit test using Visual Studio 2015 Enterprise, but this unit test uses JustMock.
When I try to profile the test, it returns with the following exception:
"Telerik.JustMock.Core.ElevatedMockingException:
Cannot mock 'ActuIT.Futurama.Config.Settings'. The profiler must be enabled to
mock, arrange or execute the specified target.
Detected
active third-party profilers:
*
{C60A40F7-B6A2-428C-8E87-E1BF6563F650} (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."
I've already linked the "Visual Studio 2015 Code Coverage/IntelliTrace" profiler in the Justmock settings, but this didn't change a thing.
Does anyone have a solution?
Hi
Does JustMock support unit testing for ASP .Net Core projects?
I am facing some dependency issues when i use JustMock to test ASP .Net Core project.
Thanks and Regards
Sujin
01.
using
System;
02.
using
System.Collections.Generic;
03.
using
Microsoft.VisualStudio.TestTools.UnitTesting;
04.
using
Telerik.JustMock;
05.
06.
namespace
JustMockTestProject
07.
{
08.
public
interface
IFoo
09.
{
10.
IBar Bar {
get
; }
11.
}
12.
13.
public
interface
IBar : IEnumerable<Object>
14.
{
15.
IBaz GetBaz();
16.
}
17.
18.
public
interface
IBaz {}
19.
20.
[TestClass]
21.
public
class
JustMockTest
22.
{
23.
[TestMethod]
24.
public
void
TestMethod1()
25.
{
26.
var foo = Mock.Create<IFoo>(Behavior.RecursiveLoose);
27.
var bar = Mock.Create<IBar>(Behavior.RecursiveLoose);
28.
29.
Assert.IsNotNull(bar.GetBaz());
// passes
30.
Assert.IsNotNull(foo.Bar.GetBaz());
// fails
31.
}
32.
}
33.
}
I am trying to test async method but i am getting null reference exception.
I have a service that has a GetAll method which is async: public async Task<IQueryable<T>> GetAll()
and the method under test is calling this method: await _service.GetAll();
I am mocking the service and then doing an arrange on the getAll method, but i get a null reference exception when the method is called in the code under test.
Mock.Arrange(() => mockService.GetAll()).Returns(Task.FromResult<IQueryable<Models.VM>>(vms.AsQueryable()));
Thanks
Vikas Mittal
Sorry if this is a noob question on JustMock, but I'm still learning the package.
VS 2017 Enterprise 15.2(26430.6) Release
.NET Framework 4.6.01586
XUnit.net 2.2.0
JustMock 2017.2.502.1
Created a unit test for testing an email module where I'm mocking the SmtpClient to keep it from actually sending emails in unit tests. When I run the tests either all together or individually, they run properly. When I attempt to use the Test->Analyze Code Coverage, several of them fail with:
Message: Telerik.JustMock.Core.ElevatedMockingException : Cannot mock
'Void Send(System.Net.Mail.MailMessage)'
. 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.
I've tried some of the suggestions I've found in other forum topics like disabling Intellitrace, running VS elevated and enabling the VS2015 Intellitrace option in the JustMock Options menu. None of these combinations appear to make any difference. As it is, I'm unable to view code coverage using these unit tests which limits the usability.
Here's the code that passes except under Analyze Code Coverage:
var log = Mock.Create<ILog>();
Mock.Arrange(() => log.InfoFormat(EMailModule.Properties.Resources.Email_Send_log_SendingMessage,
_validSubject)).OccursAtLeast(1);
var smtpClient = Mock.Create<SmtpClient>(Behavior.CallOriginal);
Mock.Arrange(() => smtpClient.Send(Arg.IsAny<MailMessage>()))
.IgnoreArguments()
.IgnoreInstance()
.DoNothing()
.OccursOnce();
var mail =
new
Email(log, _testSMTPServer);
mail.Sender =
new
MailAddress(_validSender);
mail.EmailAddressesTo.Add(
new
MailAddress(_validEmail));
mail.Subject = _validSubject;
mail.Send();
Mock.Assert(smtpClient);
Mock.Assert(log);
Anyone have any suggestions? Is this a bug, a known issue with VS2017 and JustMock or just me being too new to JustMock a.k.a.I screwed something up?
Hi,
I have 2 interfaces (I1 and I2) that have a property called FileName. Another interface is inheriting these two interfaces. Let us call it I3.In I3, I am using new modifier (this is C#) so that in my code I do not get FileName property displayed twice and prevent compiler ambiguity errors.
When I mock interface I3 and set the FileName value, this value does not propagate to interfaces I1 and I2. This is not an issue in my actual code.
I have attached a sample pictures of the code. The first assert works. Second and third fail.
Assert.IsTrue(toTest.FileName == @"test file name", "FileName missing"); //1
Assert.IsTrue((toTest as Interface1).FileName== @"test file name","FileName missing"); //2
Assert.IsTrue((toTest as Interface2).FileName == @"test file name", "FileName missing"); //3
Am I doing something wrong OR is this a bug with the lite version of JustMock?
Thank you for time taken to read and any direction to resolve my challenge.
Sainath
Hi there
Is there any early access program or something similar for JustMock? Due to some license problems I had to move to Visual Studio 2017 RC and now I desperately need the JustMock Profiler...
Any chance?
Thank you for your help
Mike
[ClassInitialize()]
public
static
void
MyClassInitialize(TestContext testContext)
{
Mock.Partial<EagleUtility>().For(() => EagleUtility.ValidateMessage(Arg.IsAny<byte[]>(), Arg.AnyInt, TowerTypes.Unified)); Mock.Partial<UnifiedProtocolTranslator>();
}
public
void
RecieveIncomingMessageTest()
{
var expectedTower = TestContext.DataRow[
"Tower"
].ToString();
var expectedEventDescription = TestContext.DataRow[
"EventDescription"
].ToString().TrimStart(
'\r'
,
'\n'
,
' '
);
expectedEventDescription = expectedEventDescription.TrimEnd(
' '
,
'\n'
,
'\r'
,
'\0'
);
var rawDataToUse = Convert.FromBase64String(TestContext.DataRow[
"RawData"
].ToString());
var called =
false
;
var target =
new
UnifiedProtocolTranslator();
;
int
byteCount = rawDataToUse.Length;
EagleIncomingMessageStatus expected = EagleIncomingMessageStatus.Complete;
EagleIncomingMessageStatus actual;
Mock.NonPublic.Arrange<bool>(target, "ProcessIncomingMessage", rawDataToUse, 0).IgnoreArguments().DoInstead((byte[] arg1,int arg2) => called =true).Returns(true).MustBeCalled();
Mock.NonPublic.Arrange(target,
"CompileIncomingMessage"
).DoNothing().MustBeCalled();
actual = target.RecieveIncomingMessage(rawDataToUse, byteCount);
Mock.Assert(target);
Assert.AreEqual(expected, actual);
}
public
EagleIncomingMessageStatus RecieveIncomingMessage(
byte
[] message,
int
byteCount)
{
var messageType = (UnifiedIncomingMessageTypes) message[0];
EagleIncomingMessageStatus returnValue = EagleIncomingMessageStatus.Continue;
if
(EagleUtility.ValidateMessage(message, byteCount, TowerTypes.Unified))
{
if
(ProcessIncomingMessage(message, byteCount))
{
CompileIncomingMessage();
returnValue = EagleIncomingMessageStatus.Complete;
}
}
return
returnValue;
}
Just started getting this on multiple machines trying to execute tests via the Resharper Test Runner while collecting coverage via dotcover. Profiling is enabled and dotcover is selected as an additional profiler. This configuration has been working for a while, its a very large solution with 100's of devs so its very possible a version changed etc. Just looking for some direction on where to start looking.
At the same time of the errors I see the following two entries in the System Event Log.
.NET Runtime version 4.0.30319.0 - The profiler was loaded successfully. Profiler CLSID: '{b7abe522-a68f-44f2-925b-81e7488e9ec0}'. Process ID (decimal): 180616. Message ID: [0x2507].
.NET Runtime version 2.0.50727.5485 - Failed to CoCreate profiler.
System.Runtime.Serialization.SerializationException
Type 'Telerik.JustMock.Core.Behaviors.EventStubsBehavior+EventsMixin' in Assembly 'Telerik.JustMock, Version=2016.1.307.3, Culture=neutral, PublicKeyToken=721b6c5bc0326b3a' is not marked as serializable.
Server stack trace:
at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeMessageParts(ArrayList argsToSerialize)
at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage..ctor(IMethodCallMessage mcm)
at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.SmuggleIfPossible(IMessage msg)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Xunit.Abstractions.IMessageSink.OnMessage(IMessageSinkMessage message)
at Xunit.Sdk.SynchronousMessageBus.QueueMessage(IMessageSinkMessage message) in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\SynchronousMessageBus.cs:line 24
at ReflectionAbstractionExtensions.CreateTestClass(ITest test, Type testClassType, Object[] constructorArguments, IMessageBus messageBus, ExecutionTimer timer, CancellationTokenSource cancellationTokenSource) in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Extensions\ReflectionAbstractionExtensions.cs:line 45
at Xunit.Sdk.TestInvoker`1.CreateTestClass() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 121
at Xunit.Sdk.TestInvoker`1.<<RunAsync>b__45_0>d.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.execution\Sdk\Frameworks\Runners\TestInvoker.cs:line 160
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Xunit.Sdk.ExceptionAggregator.<RunAsync>d__10`1.MoveNext() in C:\BuildAgent\work\cb37e9acf085d108\src\xunit.core\Sdk\ExceptionAggregator.cs:line 107