Called contructor parameter asserts

2 posts, 0 answers
  1. Zsolt
    Zsolt avatar
    1 posts
    Member since:
    Oct 2012

    Posted 24 Nov 2012 Link to this post

      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.

  2. Ricky
    Ricky avatar
    467 posts

    Posted 26 Nov 2012 Link to this post

    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
    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top