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

Unit tests failing Gated Check-in

3 Answers 31 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sunil
Top achievements
Rank 1
Sunil asked on 05 Jan 2016, 06:46 PM

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

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 06 Jan 2016, 10:38 AM
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
0
Sunil
Top achievements
Rank 1
answered on 06 Jan 2016, 05:25 PM

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.

0
Stefan
Telerik team
answered on 07 Jan 2016, 07:31 AM
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
Tags
General Discussions
Asked by
Sunil
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Sunil
Top achievements
Rank 1
Share this question
or