title: TestNG: Should running tests by tests by method or class call the @BeforeSuite method?
body: <p>I have a suite of tests that has a setUp method annotated with @BeforeSuite which runs before the suite. Occasionally I will need to run tests individually or all tests in a class. Is there a way to get my setUp method to run before these too. </p>
  
  <p>My understanding is that TestNG creates a default suite so it shouldn't matter how I run the tests, if I have a method annotated with @BeforeSuite it should run before all tests. However this doesn't work for me. It runs only when I run the full suite.</p>
  
  <p>xml suite. If I run a test from here it works. (right-click, select run)</p>
  
  <pre><code>&lt;!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" &gt;
  &lt;suite name="OvernightSuite"&gt;
  &lt;test name="Test Sequential" preserve-order="true" parallel="none"&gt;
      &lt;classes&gt;
          &lt;class name="com.myComp.test.cases.setUpClass" /&gt;
          &lt;class name="com.com.myComp.test.cases.testClass1" /&gt;
          &lt;class name="com.com.myComp.test.cases.testClass2" /&gt;
      &lt;/classes&gt;
  &lt;/test&gt;
  &lt;/suite&gt;
  </code></pre>
  
  <p>Set-up class</p>
  
  <pre><code>public class setUpClass{
  @BeforeSuite
  public void setUp() {
      populateDataSources();
      populateVariables();
  }
      @Test
      public void datasourcesWereSetUpTest() {
          boolean result = method.read();
          assert(result);
      }
  }
  </code></pre>
  
  <p>One of the test classes. If I run here, (highlight, right-click, select run) the beforeSuite is not executed.</p>
  
  <pre><code>public class testClass1{
      @Test
      public void someTest() {
          boolean result = method.read();
          assert(result);
      }
  }
  </code></pre>