Question

Im facing the problem in the order of printing the output.

Can anyone tel me how to print in the same order as method mentioned. And why is printing wrongly in console.

Class file

@Test(groups={"orderBo", "save"})
    public void testMakeOrder() {  
      System.out.println("testMakeOrder1");
    }  

    @Test(groups={"orderBo", "save"})
    public void testMakeEmptyOrder() {  
      System.out.println("testMakeEmptyOrder2");
    }  

    @Test(groups="orderBo")
    public void testUpdateOrder() {  
        System.out.println("testUpdateOrder3");
    }  

    @Test(groups="orderBo")
    public void testFindOrder() {  
        System.out.println("testFindOrder");
    }  
    @Test(groups="db")
    public void testDb1() {  
        System.out.println("testDb1");
    }
    @Test(groups="db")
    public void testDb2() {  
        System.out.println("testDb2");
    }

Testng.xml

<suite name="TestAll">

  <test name="database">
    <groups>
        <run>
            <include name="orderBo" />
            <exclude name="brokenTests" />
            <include name="db" />

        </run>
    </groups>

    <classes>

        <class name="com.mkyong.testng.examples.suite.TestOrder" />
    </classes>
  </test>

</suite>

OUTPUT: testDb1 testDb2 testFindOrder testMakeEmptyOrder2 testMakeOrder1 testUpdateOrder3

Thanks in advance.

Was it helpful?

Solution

There are a few ways I know of that you can force order:

  1.  Use  <suite preserve-order="true">
  2.  Use  <test preserve-order="true">
  3.  External suite files always run in order so you can group tests into 
      separate external suite config files and call them from a master.
  4.  Use @Test(dependsOnMethods = { "serverStartedOk" })

Also, JUnit has a alphabetical order option i think.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top