Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

TestNG - Problem with skipping

 
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
author & internet detective
Posts: 40722
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Srikanth Raghavan
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
author & internet detective
Posts: 40722
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic