Telerik Forums
JustMock Forum
3 answers
145 views

Like the user in this thread I'm having a problem getting my unit tests running in TFS. In my case, I'm running TFS 2012. However, having read through the thread I assumed that the process to fix it would be the same.

A little more reading and I found this documentation article and I followed the steps shown there. In my case I followed the "Steps for integrating JustMock in updated build configurations (DefaultTemplate.11.1.xaml)".

I set up the Build Controller to get the required assemblies (jm01.png)

I modified the build template (jm02.png)

After checking in the modified template I ran my build. It failed.

"Test method Genesis.Service.Implementation.Tests.Digests.WeeklyDigestFixture.ShouldCallAllSections threw exception: 
Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'Int32 get_DigestsToBeIncludedOn()'. The profiler must be enabled to mock, arrange or execute the specified target.
"

 Thinking I must have missed a step and that the profiler wasn't working I investigated further.

jm03.png and jm04.png, however, suggest that I didn't.

So why are my tests failing?

Stuart Hemming
Top achievements
Rank 2
 answered on 05 Jun 2015
1 answer
158 views

In a test method, I'm trying to mock an AutoMapper call and return the object I created in my test method:

 Mock.Arrange(() => _mappingEngine.Map<DtcIgnoreModel, DTCIgnore>(dtcIgnoreMockObj, Arg.IsAny<DTCIgnore>())).Returns(dtcIgnore);

But I get an IndexOutOfRangeException when I hit this line. Says it "occurred in Telerik.JustMock.dll but was not handled in the user code. Additional Information: Index was outside the bounds of the array."

I'm not sure what array it's referring to. Any advice would be appreciated.

 

-L

Kaloyan
Telerik team
 answered on 03 Jun 2015
3 answers
119 views

Hi.

My configuration: Visual Studio 2015 preview version + JustMock Q2 (2015.2.512.4)

Apparently static mocking doesn't work for me when i run it from Windows Universal unit test project. It seems ignoring the mock at all. For example here it doesn't throw exception:

Mock.SetupStatic(typeof(Assert), Behavior.Strict);
Mock.Arrange(() => Assert.IsTrue(Arg.AnyBool)).Throws(new ArgumentException());
Assert.IsTrue(true);

The same code executes correctly if i create regular unit test project on the same configuration.

 Any help?

Thanks.

Kaloyan
Telerik team
 answered on 25 May 2015
1 answer
149 views

I'm trying to make a mock that verifies that none of the Error or ErrorFormat calls on the log4net ILog interface were called. Given the number of various signatures this seems a bit annoying. Any better ideas that literally making a match for all 7? The .IgnoreArguments() isn't that helpful given I need to match each signature first before ignoring and putting all nulls causes ambiguous call errors so I have to use Arg.IsAny<> all over.

Signatures I want matched:
void Error(object message);

void Error(object message, Exception exception);

void ErrorFormat(string format, params object[] args);

void ErrorFormat(string format, object arg0);

void ErrorFormat(string format, object arg0, object arg1);

void ErrorFormat(string format, object arg0, object arg1, object arg2);

void ErrorFormat(IFormatProvider provider, string format, params object[] args);

Example of matching:

            Mock.Arrange(() => _Logger.Error(Arg.IsAny<object>())).OccursNever();
            Mock.Arrange(() => _Logger.Error(Arg.IsAny<object>(), Arg.IsAny<Exception>())).OccursNever();
... do I have to do all 7 this way?

Stefan
Telerik team
 answered on 19 May 2015
2 answers
153 views

@SET JUSTMOCK_INSTANCE=1
@SET COR_ENABLE_PROFILING=1
@SET COR_PROFILER={B7ABE522-A68F-44F2-925B-81E7488E9EC0}

When I run XUNIT, this works fine. : 

xunit.console %TestsDLL% -nunit %ReportDirectory%\%CurrentProjectRunning%.%ldt%.xml

Results: 

.NET Runtime version 4.0.30319.0 - The profiler was loaded successfully.  Profiler CLSID: '{B7ABE522-A68F-44F2-925B-81E7488E9EC0}'.  

 No error the profiler seems to work. 

 

When I run XUNIT from OpenCover it seems to lose these settings?

 OpenCover.console.exe -target:"c:\xunitrunner\xunit.console.exe" -mergebyhash -filter:"+[*]*" -targetargs:"%TestsDLL% -nunit %ReportDirectory%\%CurrentProjectRunning%.%ldt%.xml"  -output:%ReportDirectory%\%ldt%coverage.xml -register:user

Results:

.NET Runtime version 4.0.30319.0 - The profiler was loaded successfully.  Profiler CLSID: '{1542C21D-80C3-45E6-A56C-A9C1E4BEB7B8}'.  

With this error:
The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* OpenCover (from process environment)
Disable the profilers or link them from the JustMock configuration utility. Rest
art the test runner and, if necessary, Visual Studio after linking.

 

Kaloyan
Telerik team
 answered on 18 May 2015
0 answers
70 views

Hi.

My configuration is: Visual Studio 2015 preview + JustMock Q2 2015 (2015.2.512.4)

Apparently static mocks don't work for me when i execute them from Windows Universal unit test project. It seems like the mock is not applied at all and the actual code is executed. For example here exception is not thrown:

Mock.SetupStatic(typeof(Assert), Behavior.Strict);
Mock.Arrange(() => Assert.IsTrue(Arg.AnyBool)).Throws(new ArgumentException());
Assert.IsTrue(true);

The same code though executes correctly and exception is thrown when i execute it from the regular unit test project.

Thank you.

 

Anton
Top achievements
Rank 1
 asked on 15 May 2015
3 answers
209 views

Hi Telerik team,

 

Is it possible to use Mock.Arrange to mock a C++/CLI function that has parameters which are pointers to native C++ structs? Function prototype would be similar to the following:

int foo(NativeStruct1* param1, NativeStruct2* param2)

 

Best Regards,

David

 

Stefan
Telerik team
 answered on 15 May 2015
2 answers
585 views

I've found a couple of articles about testing protected methods and have written the appropriate code to do so.

However, now I want to test my class, which includes a public abstract method, to ensure, when the abstract method is called in this particular implementation, that one or more protected methods are called. Something like this ...

01.public abstract class MyBaseClass
02.{
03.    protected void Foo(){ /* stuff */ }
04.    protected void Bar(){ /* stuff */ }
05.     
06.    public abstract void Stuff();
07.}
08. 
09.public class MyClass : MyBaseClass
10.{
11.    public override void Stuff()
12.    {
13.        Bar();
14.    }
15.}

 

In this trivial example I want my test to ensure that Bar() is called.

 Can I actually do this?

Stefan
Telerik team
 answered on 12 May 2015
10 answers
539 views
Hello There,

I have just upgraded JustMock Q2, 2013. I have around 60+ unit test cases. If I run all of them they are successful. But if I run Code Coverage around 40+ are failing and the common error message for all these failed test cases is as below. Is this still a bug in Q2.
Before Q2 2013 release i was not even able to run all the test cases at a time. I have to run part by part to make them pass.

By the way I have enable Profiler under telerik menu in VS 2012.

Telerik.JustMock.Core.ElevatedMockingException: Cannot mock 'Telerik.Windows.DragDrop.DragEventArgs'. The profiler must be enabled to mock, arrange or execute the specified target.
Result StackTrace:
at Telerik.JustMock.Core.MocksRepository.Create(Type ‹, Object[] €, IEnumerable`1 ˆ–, IEnumerable`1 ‰–, IEnumerable`1 Š–, Type[] ‚–, Boolean ƒ–, Boolean €, IEnumerable`1 ˆ)
   at .‹–.Create(MocksRepository €–, Type ‹, Object[] –, Nullable`1 , Type[] ‚–, Nullable`1 ƒ–, IEnumerable`1 ˆ, List`1 ‰–, List`1 Š–, List`1 ˆ–)
   at Telerik.JustMock.Mock.—.ˆŸ()
   at “•.’•.Š•[–](Func`1 ‹•)
   at Telerik.JustMock.Mock.Create[T](Constructor constructor)
   at Project.Modules.Content.Test.ContentViewModelTest.Content_ContentViewModel_AddDatePicker_ArePropertiesAdded() in c:\Project\Dev\Source\Client\UnitTest\Project.Modules.Content.Test\ContentViewModelTest.cs:line 339

Stefan
Telerik team
 answered on 12 May 2015
3 answers
200 views
Hello Telerik Team
I use Just Mock  and i want to mock a private method with 2 out arguments
how to achieve it
for example

private void myMethod(string x, string y, out bool isFound, out string result)

Stefan
Telerik team
 answered on 07 May 2015
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?