Run method before typing in TestNG via XML

I have an XML TestNG test suite:

<suite name="mySuite" parallel="classes" thread-count="5">
    <test name="myTest">
        <packages>
            <package name="mypack.*"/>
        </packages>
    </test>
</suite>

and I would like to run the method every time before the package.

Is it possible to have something like this:

<suite name="mySuite" parallel="classes" thread-count="5">
    <before-suite>...</before-suite> <!-- Here I want to run a single method  -->
    <test name="myTest">
        <packages>
            <package name="mypack.*"/>
        </packages>
    </test>
</suite>

?

+4
source share
2 answers

There are two options:

  • Use the @BeforeSuite annotation for your method that you want to run before each batch
  • Add the ISuiteListener onStart method, add the implemented listener to your XML in the listeners section.
+1
source

According to the TestNG documentation ( http://testng.org/doc/documentation-main.html ), we have no way to specify the before suite method in testng.xml.

, , .

public class UtilitiesTest {
     @BeforeSuite
     public void init() {
         // Initialize the system before the test suite.
     }
}

, , @BeforeTest, @BeforeClass, @BeforeMethod ..., .

. .

+1

Source: https://habr.com/ru/post/1680808/


All Articles