title: Multiple levels of setUp/tearDown in TestNG?
body: <p>In using TestNG for my Selenium framework, the setUp method is relatively complex. There are multiple points that it can break and I would like to split it into separate steps.</p>
  
  <p>Ideally it would look something like this:</p>
  
  <pre><code>// Does some DB stuff, logs some messages
  @BeforeMethod(alwaysRun = true)
  preTestCase
  
  
  // Instantiates and opens up Selenium
  @BeforeMethod(dependsOnMethods = {"preTestCase"})
  seleniumSetup
  
  
  // Closes Selenium only if it was properly setup
  @AfterMethod(dependsOnMethods = {"seleniumSetup"})
  seleniumTearDown
  
  
  // All other test case teardown, error logging
  @AfterMethod(alwaysRun=true)
  postTestCase
  </code></pre>
  
  <p>What I want to avoid is failing in preTestCase due to a DB issue and then getting a secondary failure due to seleniumTearDown trying to close a non-existent instance. In that situation, only postTestCase should be run. I am getting this error: seleniumTearDown() is not allowed to depend on public void seleniumSetUp(org.testng.ITestContext). Is this not allowed / bad design? How do I enforce run-order between the two tearDown methods so that postTestCase() is always run last, regardless of if seleniumTearDown is run?</p>