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.
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityorg.testng.Assert.fail("you wandered onto the wrong path");
You can always throw exception -
if("this path is followed") {
throw new Exception("was bound to fail!!!")
}
AssertionError
instead of Exception
(which is what Assert.fail()
does under the covers) would be better and would prevent the error from being swallowed by a catch (Exception)
block. Of course, catch (Exception)
is generally a bad idea anyways...