I have an XML TestNG suite:
<suite name="mySuite" parallel="classes" thread-count="5">
<test name="myTest">
<packages>
<package name="mypack.*"/>
</packages>
</test>
</suite>
and I'd like to run a method every time before the suite.
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>
?
There are 2 options you have:
As per the documentation of the TestNG (http://testng.org/doc/documentation-main.html), we don't have an option to specify the before suite method in testng.xml.
As an option, you can use before suite annotation as follows to satisfy the requirement.
public class UtilitiesTest {
@BeforeSuite
public void init() {
// Initialize the system before the test suite.
}
}
If you refer the documentation, you will find there are lots of annotations such as @BeforeTest, @BeforeClass, @BeforeMethod ...
might be helpful.
Note: You can place this class anywhere in the test suite.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With