We are expanding our TestNG suite to run multiple tests. Doing so we've encountered a strange occurrence.

In one suite I have two tests. Both tests have one class each. Tests in IntegrationTest.java has a @BeforeClass annotation.

This is my testng.xml:

<suite name="Suite">
  <test name="Test">
      <class name="testng.Jenkins"/>
  <test name="Test2">
      <class name="testng.integrationTest.IntegrationTest"/>

Two tests, one class each.

Below is my TestNG output console:

enter image description here

There is no mention of the method under @BeforeClass annotation in IntegrationTest.java.

The method got executed (it has sysout in the console) but it is not shown in this TestNG results console.

Shouldn't @BeforeClass execute before @Test?

This the class:

public class IntegrationTest {

    //public void beforeSuite() {
    //  System.out.println("Before suite");

    public void beforeClass() {

        System.out.println("Before class");open("http://www.google.com");

    public void IDEEACamsEndtoEndTest() {

        System.out.println("Actual test");



So, @BeforeCLass method doesn't get displayed in TestNG output window (picture above) until I uncomment @BeforeSuite. Then both get displayed (picture below):

enter image description here

  • For one thing, in test frameworks, BeforeClass annotated method is usually static, which means is acts like a regular static initializer block. Now, if your test runner forks threads "by test method" rather than by "test class" then your tests might have trouble interacting with the class level instance. Just FYI.
    – djangofan
    Jun 5, 2020 at 22:06


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.