Static mock doesn't work for Windows Universal unit tests

4 posts, 0 answers
  1. Anton
    Anton avatar
    4 posts
    Member since:
    Mar 2015

    Posted 15 May 2015 Link to this post

    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.

  2. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 19 May 2015 Link to this post

    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
  3. DevCraft R3 2016 release webinar banner
  4. Anton
    Anton avatar
    4 posts
    Member since:
    Mar 2015

    Posted 20 May 2015 Link to this post

    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.

  5. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 25 May 2015 Link to this post

    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
Back to Top