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

Called contructor parameter asserts

1 Answer 12 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Zsolt
Top achievements
Rank 1
Zsolt asked on 24 Nov 2012, 02:17 PM
Hello,
  could you show me an example of the following scenario?

class A
{
  public DoSomething() { B b = new B(23, "apple"); }
}

I want to assert A.DoSomething calls B's contructor with 23 and apple parameters.

Thanks,
Zsolt

1 Answer, 1 is accepted

Sort by
0
Ricky
Telerik team
answered on 26 Nov 2012, 07:23 PM
Hi Zsott,

Thanks again for contacting us. 

Ideally, mocking tools fake a part of your code so that you can test SUT (System Under Test) as expected. Here If you are mocking a method from class B then you can use IgnoreInstance or future mocking to skip / assert that call. Furthermore it’s a best practice to move your logical code to a different method which will be called from the constructor and then it will be right to mock/assert that method.

Having logical codes (other than variable initialization) inside constructor makes a class more fragile and hard to mock. In addition, mocking tools should have some restriction to make developer write better code.  

Finally, we have included the scenario into our product plan so that it is also possible to assert a constructor called with expected arguments although this is not always the best practice.

Kind Regards
Mehfuz
the Telerik team
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
General Discussions
Asked by
Zsolt
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Share this question
or