Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As your question is written you do not need to setup the myTestObj_mock.do_work(). </p> <p>Setup is used to say, when method X is called return value Y. Or alternativly that when method X is called, exception Z is returned. Ask yourself is that really what I need to do?</p> <p>Here you aren't returning anything from the method:</p> <pre><code>mto.do_work( this ); </code></pre> <p>Also, here: </p> <pre><code>myTestObj_mock.Setup( e =&gt; e.do_work( It.IsAny&lt; AnObject &gt; () ) ); </code></pre> <p>You aren't defining any Return for your setup.</p> <p>You should be able to supply a mock myTestObj_mock without defining the setup in this case. Just remove the line with the Setup and run the test again.</p> <p><em>A guess:</em></p> <p>If you defined the Setup because you wanted your test to make sure AnObject.AnAction really calls the do_work method, what you need to do is define a Verify method rather than a Setup, likewise:</p> <pre><code>mock.Verify(foo =&gt; foo.Execute("ping")); </code></pre> <p>or in your case something like </p> <pre><code>myTestObj_mock.Verify(m =&gt; m.do_work(It.IsAny&lt; AnObject &gt; ()), Times.AtLeastOnce()); </code></pre> <p><em>Another guess:</em></p> <p>If you defined the mock because you pass a "this" reference and expect do_work to modify some parameters of "this" for the test to pass then you shouldn't be mocking here. Remember that mocks aren't really instances of your objects, so the code that modify the this reference will never get called. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload