Search code examples
javamaventestngsequential

How to run maven tests sequentially


I have different class with each class have one or more tests.

I want to run the maven tests with each class in a sequential order using testing.xml

testing.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1" verbose="1">
    <test name="Regression1">
        <classes>
            <class name="test.settings.SettingsTest"/>
            <class name="test.weather.WeatherTest"/>
        </classes>
    </test>
</suite>

When i ran below command , its runs all the test. But i want to run the test specified in testing.xml one by one on sequential order.

mvn -Dtests=testing.xml test

Solution

  • I have missed the configuration in maven-surefire-plugin

    Here is what i tried

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

    In testing.xml

    <test name="Regression1" parallel="false" preserve-order="true">
    

    its works now.