Meaningless Drivel is fun!*
The moose likes Testing and the fly likes TestNG - Problem with skipping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "TestNG - Problem with skipping" Watch "TestNG - Problem with skipping" New topic
Author

TestNG - Problem with skipping

Srikanth Raghavan
Ranch Hand

Joined: Oct 31, 2005
Posts: 389
Hi,

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:

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Srikanth Raghavan
Ranch Hand

Joined: Oct 31, 2005
Posts: 389
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

Thanks,
Srikanth
Timothy Frey
Ranch Hand

Joined: Jul 22, 2006
Posts: 56
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.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

Originally posted by Srikanth Raghavan:
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 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?
Srikanth Raghavan
Ranch Hand

Joined: Oct 31, 2005
Posts: 389
Originally posted by Jeanne Boyarsky:

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: TestNG - Problem with skipping
 
Similar Threads
problem with oops method::
Thread
exception handling in instance initializer
Thread and Pipes problem.
how to simulate multi-thread to test Data ?