Galet
Galet

Reputation: 6269

How to run a multiple class with multiple testng test in sequential order using maven on java

In pom.xml

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testing.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>

In testing.xml

<suite name="Suite1" verbose="1">
    <test name="Regression1" parallel="false" preserve-order="true">
        <packages>
            <package name="apps.sample.test1.*" />
            <package name="apps.sample.test2.*" />
        </packages>
        <classes>
            <class name="apps.sample.test1.Test1.java" />
            <class name="apps.sample.test1.Test2.java" />
        </classes>
    </test>
</suite>

apps.sample.test1.* contains following 1. apps.sample.test1.Test1.java

@BeforeClass
public void test1(Method method) throws Exception {
}

@Test(priority=1)
public void test2(Method method) throws Exception {
}

@Test(priority=2)
public void test3(Method method) throws Exception {
}

@Test(priority=3)
public void test4(Method method) throws Exception {
}

When I ran testing.xml, All @BeforeClass from all Class files are getting executed first and then @Test(priority=1) methods gets executed from all class are executed one by one.

Due to above scenario, my @Test(priority=2) from all class files are failing.

how can make my test to be executed in order based on priority for a every class and class should be executed one by one ?

Upvotes: 2

Views: 979

Answers (1)

Gaurav
Gaurav

Reputation: 1370

You can use dependOnMethod testng feature. Do this:

@Test
public void test2(Method method) throws Exception {
}

@Test(dependsOnMethods = "test2")
public void test3(Method method) throws Exception {
}

@Test(dependsOnMethods = "test3")
public void test4(Method method) throws Exception {
}

Upvotes: 1

Related Questions