Unit tests failing Gated Check-in

4 posts, 0 answers
  1. Sunil
    Sunil avatar
    2 posts
    Member since:
    Jan 2016

    Posted 05 Jan Link to this post

    Hi,

    I am new to justmock, bear with me if I have some basic questions wrong.

    We have few unit tests that run fine when I run them locally, but when I checkin them in TFS then it fails the gated-checkin.

    I know this can be  caused from a range of reasons, but I have reason to believe that one of the mocked method is not getting mocked in the server.

    Here is how the code looks, 

     

     

    public void My_Failing_Test()
        {              
         Test_Class_Accessor target = new Test_Class_Accessor();        
         target.DataLayer = GetMockLayer();
        // Set up data 
         Test_Class mockTest = new Test_Class();
         Mock.NonPublic.Arrange<bool>(mockPharm, "MockedPrivateMethod", ArgExpr.IsAny<String>(), ArgExpr.IsAny<String>(), ArgExpr.IsAny<DateTime>()).IgnoreArguments().IgnoreInstance().Returns(false);
         target.UnderTestPrivateMethod();
         //Asserts     
        }

     UnderTestPrivateMethod has a call to MockedPrivateMethod

     

    private static DataLayer GetMockLayer(......)
         {
             Features mockFeatures = Mock.Create<Features>(Constructor.NotMocked, Behavior.CallOriginal);
              
                 mockFeatures.someThing = new SomeThing{.....};
           
     
             DataLayer mockLayer = Mock.Create<DataLayer>(Constructor.NotMocked, Behavior.CallOriginal);
             mockLayer.TwoTier_Initialize();
     
             Mock.Arrange(() => mockLayer.Features).Returns(mockFeatures);
     
        
     
             return mockLayer;
         }

     

    I suspect for some reason both the mockFeatures.someThing and MockedPrivateMethod are not getting mocked.

    Is there something wrong with what I am doing? 
    If someone has faces similar problem before, please let me know.

    Appreciate the time, thanks

  2. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 06 Jan Link to this post

    Hello Sunil,

    How does the test fail? Is it a JustMock exception, or something else? Do you use elevated mocking, or just JustMock Lite? My guess is that you use elevated mocking and you haven't  installed JustMock on the build agents.


    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. Sunil
    Sunil avatar
    2 posts
    Member since:
    Jan 2016

    Posted 06 Jan in reply to Stefan Link to this post

    These test cases are passed on my local machine when I run them.

    Test fails due to some exception in  function MockedPrivateMethod, this shouldn't happen because I have mocked this.
    Justmock is installed because there are other test cases that run perfectly fine.

    Do I have to intercept my method? because there are chances some other unit tests may call this before my test is executed.

  5. Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 07 Jan Link to this post

    Hello Sunil,

    You don't have to intercept the method, if you use a recent version of JustMock. Method arrangements are confined to within the test method they're declared in and will not leak out. Also, tests running beforehand do not affect subsequent mocking. I see that your test is not using async code, which is a common reason for sporadic test failures. If you can give me the complete test that fails together with the occurring exception, I might be better able to help you out, as I'm just guessing in the dark right now.

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