I have two classes and each class contains 2 test cases and Test1 class having one method with @BeforeClass as per me this method should run before Test2 class too but it is not running.
    package WebPackage;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;
    public class Test1 {
        @BeforeClass
        public void test1() {
            System.out.println("printing Before Class Method");
        }
        @Test (priority = 1)
    public void test2() {
            System.out.println("printing test_2");
        }
        @Test (priority = 3)
    public void test3() {
            System.out.println("printing test_3");
        }
    }
Test2
    package WebPackage;
    import org.testng.annotations.Test;
    public class Test2 {
        @Test (priority = 1)
        public void test4() {
                System.out.println("printing test_4");
            }
            @Test (priority = 3)
        public void test5() {
                System.out.println("printing test_5");
            }
    }
Xml file
    <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
    <suite name="Menu">
      <test name="WebPackage">
        <classes>
          <class name="WebPackage.Test1"/>
         <class name="WebPackage.Test2"/>
        </classes>
      </test> <!-- Test -->
    </suite> <!-- Suite -->
Console
[RemoteTestNG] detected TestNG version 7.0.0
printing Before Class Method
printing test_2
printing test_3
printing test_4
printing test_5
===============================================
Menu
Total tests run: 4, Passes: 4, Failures: 0, Skips: 0
===============================================
 
     
     
     
    