views:

608

answers:

3

Is there a way to make running junit test to stop after a test fails?

+3  A: 

I know that in Ant, the junit task has options "haltonerror" and "haltonfailure" that controls this behavior.

Dave Costa
+2  A: 

Yes ... this ability (or the lack of it) is built into the various TestRunners (Console, AWT, Swing, Ant, Maven or the one built into Eclipse, etc). You'll have to look for this control in the documentation for the specific platform you're using.

Steve Moyer
A: 

Let's say at one moment I detect that continuing executing the tests has no meaning. I don't want to fail rest of the tests, just signal stop of the execution. Something like RunNotifier.pleaseStop(), but it seems I don't have access to this method from the tests/setUp/tearDown themselves. So how do I do that? One thing that complicates even more the question is that I may use different TestRunners for the same test package?

Thanks!

George S.