title: TestNG is Running Classes Out of Order (Skipping Between Classes of Tests)
body: <p>I am having an issue with TestNG Selenium Webdriver 2.0, and Java. I set breakpoints and saw the strangest behavior. <br>I have several class files containing groups of tests. Each class begins with initializing some variables global to all tests in the class, including a call to another class which initializes the webdriver. Next is a @BeforeClass, and next are my @Test tests. I am running the classes from a testng.xml file. <br><br>On debugging an issue lately I found that at runtime, testNG does the following:</p>
  
  <ol>
  <li>Initialize the global variables and webdriver in class1</li>
  <li>Then skips over to the top of class2 and does the same</li>
  <li>Then skips back to class1 @BeforeClass</li>
  <li>Then runs the tests in class1 5 then skips back to class2</li>
  </ol>
  
  <p>@BeforeClass and finishes from there...  <br><br>Why would testNG behave this way. I have tried stepping through but testNG is compiled code so I can't figure out why it does not finish with class1, before step 2 above. Initializing the webdriver in class2 right after the webdriver in class1 creates an odd problem that I cannot do a driver.close() at the end of class1 without closing the driver of class2. And since class2 has already had its global variables and its webdriver initialized, when testNG finally moves back to class2 after class1 tests are finished, its webdriver initialization is ignored. Also at runtime I can see one webbrowser open up to one path (for class1) then go to another path (for class2). It's just not right. Any ideas why testNG is running in such an order?</p>