When a @BeforeMethod or an @AfterMethod fails in TestNG, the subsequent setups and the tests are skipped. How do I disable this feature? I tried setting the "alwaysRun" element to true but that didn't work either.
My code is similar to this, the @BeforeMethod occasionally fails:
Why do you want to disable the feature? I actually had the same initial thoughts as you. When I asked about it last month, Cedric explained that it works this way by design. Which makes sense to me. If something just failed, why try it again?
But Jeanne, my case is a little different. Our @BeforeMethod may fail and not always and we just want to skip that particular test for which it fails. I guess what it's doing now is absolutely fine and it should be the default behavior but there should have been a mechanism to turn off this preference.
We can still do some workaround by catching the expected exceptions and suppressing them but the code smells if we do this way
Why does your BeforeMethod fail in the first place? Typically, for a given TestCase class, the "test fixture" is the same for all tests. I would expect the behavior of the BeforeMethod stuff to be exactly the same for each test.
Is the BeforeMethod thing failing because, for some reason, each test is not independent from the others? Otherwise, if the failure happens (seemingly) randomly then that's a big problem in and of itself.
I saw the "random" example and assumed that it is just for the purposes of illustration. Can you give a real example to explain why your @BeforeMethod may fail once and then pass a few seconds later?
Sure, we are doing automation of our functional tests using Selenium for one of our web projects. Before beginning a test case, in the @BeforeMethod we clean up all the preferences that were changed in the previous test case from the UI using Selenium (a more clean way of doing this would be to clean it up from the backend but this options is currently not available for us). So, for this limitation we are okay with a 5% failure and we don't want to skip the tests.
I totally agree, this is not the way to go but we don't have the backend cleanup option
PS: In my example I illustrated my problem with a @BeforeMethod failure. Its actually @AfterMethod but I guess it's one and same as far the problem is concerned.
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads: