This is a migrated thread and some comments may be shown as answers.

Static mock doesn't work for Windows Universal unit tests

3 Answers 71 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 15 May 2015, 05:24 PM

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.

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 19 May 2015, 07:40 AM
Hi Anton,

Methods that are part of the testing framework itself are not instrumented and cannot be mocked.

To test static mocking, try arranging a user type, e.g.:
public class JustTest
{
    public static void Do() {}
}
 
...
 
Mock.Arrange(() => JustTest.Do()).Throws(new ArgumentException());

Or just check the value of Mock.IsProfilerEnabled - if it's true then everything should be working as expected.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Anton
Top achievements
Rank 1
answered on 20 May 2015, 05:12 PM

Hi Stefan.

 Your sample works. Actually Assert was just an example. I'm trying to mock another static type which is part of Windows 10 sdk. 

As i understand justmock should be able to mock any mscorlib type, correct?

Thanks.

0
Kaloyan
Telerik team
answered on 25 May 2015, 01:46 PM
Hi Anton,

JustMock should be able to mock almost all mscorlib members and types. However, it hasn't been extensively tested against Windows 10. This said, could you please share the static type you are trying to mock, so we can investigate the matter on our side. Further, if there are other types that are leading to the same faulty behavior, please share them with us as well.

Regards,
Kaloyan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Anton
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Anton
Top achievements
Rank 1
Kaloyan
Telerik team
Share this question
or