Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

Is there a way to mark a test as failed in the TestNG framework if a certain path is followed?

I know I can use system.exit(1); or something similar to mark an abnormal termination but it doesn't seem to actually mark the test as failed.

share|improve this question

2 Answers 2

up vote 3 down vote accepted
org.testng.Assert.fail("you wandered onto the wrong path");
share|improve this answer
    
this did not click on my mind –  Tarun Oct 25 '11 at 5:10
    
This is exactly what I was looking for. Thank you –  Brett K Oct 26 '11 at 15:48
    
It is rare that a question in this forum can be answered in such a definite and unambiguous way. I am glad it was useful to you. –  user246 Oct 26 '11 at 16:00
    
Two roads diverge in a wood... and I, I Assert.failed... –  corsiKa Aug 29 '12 at 14:36

You can always throw exception -

if("this path is followed") {
throw new Exception("was bound to fail!!!")
}
share|improve this answer
    
An exception does not seem to fail a test either. I might just put in some code which could never be executed. In my situation this is using some robot code inside of a webdriver test. –  Brett K Oct 24 '11 at 22:23
    
Are you handling exception in your test? –  Tarun Oct 25 '11 at 5:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.