2

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">
    <classes>
      <class name="testng.Jenkins"/>
    </classes>
  </test>
  <test name="Test2">
    <classes>
      <class name="testng.integrationTest.IntegrationTest"/>
    </classes>
  </test>
</suite>

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 {


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

    @BeforeClass
    public void beforeClass() {

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

    @Test
    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

1
  • 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
    Commented Jun 5, 2020 at 22:06

0

Your Answer

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