Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I recently wrote a series of blog posts on unit testing event sequences for objects that publish both synchronous and asynchronous events. The posts describe a unit testing approach and framework, and provides the full source code with tests.</p> <p>I describe the implementation of an "event monitor" similar in concept to what you describe and some of the previous answerers to this question have mentioned. Definitely in the right direction, as writing lots of tests without some sort of monitor pattern results in lot of messy boilerplate code.</p> <p>Using the event monitor described in my article, tests can be written like so:</p> <pre><code>AsyncEventPublisher publisher = new AsyncEventPublisher(); Action test = () =&gt; { publisher.RaiseA(); publisher.RaiseB(); publisher.RaiseC(); }; var expectedSequence = new[] { "EventA", "EventB", "EventC" }; EventMonitor.Assert(test, publisher, expectedSequence, TimeoutMS); </code></pre> <p>The EventMonitor does all the heavy lifting and will run the test (test) and assert that events are raised in the expected sequence (expectedSequence). It also prints out nice diagnostic messages on test failure. What is different from some of the approaches discussed is it does not just count, it will assert that the exact sequence specified has been followed. Also, you do not need to hook any events. That is all handled by the event monitor. The tests are therefore quite clean.</p> <p>There's a lot of detail in the posts describing the issues and approaches, and source code too:</p> <p><a href="http://gojisoft.com/blog/2010/04/22/event-sequence-unit-testing-part-1/" rel="nofollow noreferrer">http://gojisoft.com/blog/2010/04/22/event-sequence-unit-testing-part-1/</a></p>
 

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