@BeforeSuite is not called when testing one class
I have a method @BeforeSuite
called -annotated.
public class MySuiteTest {
@BeforeSuite
public static void doSomethingVeryMandatory() {
// say, boot up an embedded database
// and create tables for JPA-annotated classes?
}
}
public class MySingleTest {
@Test
public void doSomething() {
// say, tests some MyBatis mappers against the embedded database?
}
}
When I test the whole test,
$ mvn clean test
all perfectly. @BeforeSuite
executed and @Test
executed.
When I tried to test one class
$ mvn -Dtest=MySingleTest clean test
doSomethingVeryMandatory()
is not called.
This is normal?
source to share
Your @BeforeSuite and @Test are in different classes. When you run one class, testng creates a standard suite.xml package with one class. Hence your @BeforeSuite doesn't show up for testing. You can either extend MySuiteClass in your test class or create a suite file and run the package file as suggested in the comments.
source to share
Babule's comment on the question works great, just giving examples for future readers:
- Create a set in XML TestNG configuration file:
<suite name="Suite Name" verbose="0">
<test name="TestName">
<classes>
<class name="MySuiteTest"/>
<class name="MySingleTest"/>
</classes>
</test>
</suite>
- Calling this config file using maven in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>config/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
source to share