Re: [nunit-discuss] Fail a testcase when event occurs

16 views
Skip to first unread message

Lior Friedman

unread,
Jun 21, 2012, 10:31:13 AM6/21/12
to nunit-...@googlegroups.com

On Thu, Jun 21, 2012 at 4:19 PM, cs <schandra...@gmail.com> wrote:
I am using 2.5 version of nunit. I have written a code to raise an event when a particular process starts. The event indicates that the particular test case has to fail. But after the event handler is executed, the control goes back where it was interrupted. Even i have wrote assert.fail() at the end of event handler. Please help me how to fail the test case and move on to the next case. 
 
HI 

one way that might help is to register a method on the event handler that lights a flag which later can be verified at the end of the test.
If you're using a mocking framework you might find it has the ability to do some sort of Verify.WasNotCalled (but basically this is just the fancy way of doing the same)

the issue is that most likely the event is handled on a different thread which is not part of the main flow of the test causing the fail exception to be thrown in a different context

As a side note  it can be argued that if you're  test involves starting up of new processes it might be a little bigger than a "unit" tests.
so the pain you're now having might indicate that you need to do something different.

Hope this helps
Lior


--


Lior Friedman

P.S. Follow me on TwitterLinkedIn. See you there…

Reply all
Reply to author
Forward
0 new messages