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?
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
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.
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?
@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.
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.
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
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?
private void myMethod(string x, string y, out bool isFound, out string result)