The current version of Telerik JustMock Lite does not appear to be supported on the Windows 10 UWP (RTM) platform.
(1) Can you confirm if there is active work underway for JustMock Lite to support this platform?
(2) Can you provide an indication of the estimated release date? I’ll need to make a call to determine if we need to switch to a different mocking framework depending on these timelines.
Background info
Note that UWP (Universal Windows Platform) was referred to as UAP (Universal App Platform) before RTM was released. UWP is the correct term to use for the platform going forwards. Initial project development was on a Windows 10 Universal App (UAP) project in Visual Studio 2015 RC 14.0.22823.1 (Windows 8.1 OS). We can confirm that the mocking behaviour was working with these pre-release tools. After upgrading Windows and Visual Studio from Technical Preview (UAP) to RTM (UWP), we now experience warnings during build output and any tests with mocking behaviour no longer run (throws exception).
Product versions
Microsoft Windows 10 Professional - 10.0.10240.16384 RTM x64 (2015/07/15)
Microsoft Visual Studio 2015 - 14.0.23107.10 RTM (2015/07/10)
Telerik JustMock Lite - 2015.2.715.1 (2015/07/15)
Sample code snippet
1.
[TestMethod]
2.
public
void
ExampleTest()
3.
{
4.
// This line throws an exception.
5.
var mockLogger = Mock.Create<ILogger>(Behavior.Loose);
6.
}
Sample debug console output
Exception thrown: 'System.IO.FileLoadException' in MyProj.Win10.Tests.exe
An exception of type 'System.IO.FileLoadException' occurred in MyProj.Win10.Tests.exe but was not handled in user code
Additional information: Could not load file or assembly 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
HResult: -2146234304
Source: Telerik.JustMock
Stacktrace: at Telerik.JustMock.Mock.Create[T](Behavior behavior), at MyProj.Win10.ExampleTest()
Your feedback would be much appreciated.
Thanks,
Davide
Let's say I have a class
class MyClass
{
public virtual void MyFunc1( DateTime somedate)
{}
public virtual void MyFunc2( )
{
MyFunc1(SomeObject.SentDate)
}
}
where SomeObject has a field called SentDate.
SomeObject is in a global scope and, for some reasons, I can't provide a value for it so will always be null when mocking.
I can arrange for MyFunc1() to do whatever I want but, when I call MyFunc2(), it will try to evaluate its parameter SomeOject.SentDate and, because SomeObject is null, this will fail with an exception.
Is there a way to skip the evaluation of SomeObject.SentDate parameter?
I have this code:
<p>
using
System;
using
Microsoft.VisualStudio.TestTools.UnitTesting;
using
Telerik.JustMock;
using
Telerik.JustMock.Core;
namespace
TestMock1
{
[TestClass]
public
class
UnitTest1 {
[TestMethod]
public
void
TestMethod1()
{ var mock = Mock.Create<Cls1>(); Mock.Arrange(() => mock.Func1()).Returns(2);
mock.Func2();
}
}
public
class
Cls1 {
public
Cls1()
{
}
internal
virtual
int
Func1()
{
int
x = 1;
return
x;
}
internal
virtual
int
Func2()
{
return
Func1();
}
}
}</p>
Currently we are using JustMock Lite with xUnit 1.9.2 and have test cases where we create reusable mocks for our test methods within the controller of a test class. My team bumped into an issue after performing an upgrade to version 2.0. It appears when using the constructor to mock a method from a class (for reuse in test methods) and then creating a second mocked function within the test method (which is a different method from the same class that was defined in the constructor) causes the mocked implementation of the method in the constructor to disappear.
Please see the test example below. In the test class MockIssueExample, I have test methods that verifies the return value from an interface method or virtual function. In version 1.9.2, the mocks defined in SetupMocks() returns the value of 5 within each of the test methods. When I upgrade to version 2.0, each of the mocked methods returns a value of 0 in the test method and causes my test to fail.
Note: In each of the test methods I left a line of code that fixes the issue but it requires me to copy the mocked implementation from the constructor into the test method.Has something changed in 2.0 that's causing this scoping issue? Can we mock one function within a constructor and a second method within the actual test method without losing the mock implementation that what was defined in the constructor.
Please Advise. Thanks!
public class MockIssueExample
{
private ITestMethods _testMethods;
private ClassUnderTest _classUnderTest;
private ClassTestMethods _classTestMethods;
public MockIssueExample()
{
SetupMocks();
_classUnderTest = new ClassUnderTest(_testMethods, _classTestMethods);
}
private void SetupMocks()
{
_testMethods = Mock.Create<ITestMethods>();
_classTestMethods = Mock.Create<ClassTestMethods>();
Mock.Arrange(() => _testMethods.FunctionReturnsInteger_1()).Returns(5);
Mock.Arrange(() => _classTestMethods.VirtualFunctionReturnsInteger_1()).Returns(5);
}
[Fact]
public void Virtual_function_1_should_return_the_mocked_value()
{
//Mock.Arrange(() => _classTestMethods.VirtualFunctionReturnsInteger_1()).Returns(5);
Mock.Arrange(() => _classTestMethods.VirtualFunctionReturnsInteger_2()).Returns(6);
int returnVal = _classUnderTest.GetValueReturnedFromVirtualFunction_1();
Assert.True(returnVal == 5);
}
[Fact]
public void Interface_function_1_should_return_the_mocked_value()
{
//Mock.Arrange(() => _testMethods.FunctionReturnsInteger_1()).Returns(5);
Mock.Arrange(() => _testMethods.FunctionReturnsInteger_2()).Returns(9);
int returnVal = _classUnderTest.GetValueReturnedFromInterfaceFunction_1();
Assert.True(returnVal == 5);
}
}
public interface ITestMethods
{
int FunctionReturnsInteger_1();
int FunctionReturnsInteger_2();
}
public class ClassTestMethods
{
public virtual int VirtualFunctionReturnsInteger_1()
{
return 1;
}
public virtual int VirtualFunctionReturnsInteger_2()
{
return 2;
}
}
public class ClassUnderTest
{
private readonly ITestMethods _testMethods;
private readonly ClassTestMethods _classTestMethods;
public ClassUnderTest(ITestMethods testMethods, ClassTestMethods classTestMethods)
{
_testMethods = testMethods;
_classTestMethods = classTestMethods;
}
public int GetValueReturnedFromVirtualFunction_1()
{
return _classTestMethods.VirtualFunctionReturnsInteger_1();
}
public int GetValueReturnedFromInterfaceFunction_1()
{
return _testMethods.FunctionReturnsInteger_1();
}
}
[TestFixture]
public class Class1
{
public class Individual
{
}
public class Family : Collection<
Individual
>
{
}
public interface ITest
{
int Test(Family family);
}
[Test]
public void Test()
{
var family1 = new Family();
var family2 = new Family();
var test = Mock.Create<
ITest
>();
Mock.Arrange(() => test.Test(family1)).Returns(1).MustBeCalled();
Mock.Arrange(() => test.Test(family2)).Returns(2).MustBeCalled();
var result = test.Test(family1) + test.Test(family2);
Mock.Assert(test);
}
}
01.
[TestClass]
02.
public
class
TestFixture
03.
{
04.
private
ICloneable _svc;
05.
06.
[TestInitialize]
07.
public
void
TestSetup() { _svc = Mock.Create<ICloneable>(); }
08.
09.
[TestCleanup]
10.
public
void
TestCleanup() { Mock.Assert(_svc); }
11.
12.
[TestMethod]
13.
public
void
TryStuff()
14.
{
15.
// arrange
16.
_svc = Mock.Create<ICloneable>();
17.
Mock.Arrange(()=> _svc.Clone()).MustBeCalled();
18.
19.
// act
20.
//_svc.Clone();
21.
22.
// assert
23.
}
24.
}
01.
public
class
TestFixture
02.
{
03.
private
List<
object
> _assertList =
new
List<
object
>();
04.
05.
[TestCleanup]
06.
public
void
TestCleanup() {
foreach
(var svc
in
_assertList) { Mock.Assert(svc); } }
07.
08.
private
void
CloneableMustBeCalled()
09.
{
10.
Mock.Arrange(() => _svc.Clone()).MustBeCalled();
11.
if
(!_assertList.Contains(_svc)) { _assertList.Add(_svc); }
12.
}
13.
}