Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@BeforeSuite not invoked when testing a single class

I have a @BeforeSuite-annotated method.

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

everything's fine. @BeforeSuite runs and @Tests run.

When I tried to test a single class

$ mvn -Dtest=MySingleTest clean test

doSomethingVeryMandatory() is not invoked.

Is this normal?

like image 631
Jin Kwon Avatar asked Nov 09 '22 22:11

Jin Kwon


1 Answers

Your @BeforeSuite and @Test are in different classes. When you run a single class, testng generates a default suite.xml with only one class in it. Hence your @BeforeSuite is not visible to testng. You can either extend MySuiteClass in your testclass or create a suite file and run the suite file as suggested in comments.

like image 146
niharika_neo Avatar answered Nov 14 '22 23:11

niharika_neo