Deprecation of @Test(sequential=true) for class level ordering

236 views
Skip to first unread message

Felipe Knorr Kuhn

unread,
Aug 18, 2010, 7:19:01 PM8/18/10
to testng...@googlegroups.com
Hello Cédric,

I have faced an ordering problem and I'm not sure it's related to the other threads commented recently.

Since @Test(sequential=true) has been deprecated and preserve-order has been implemented, how would you tell the TestNG engine to execute the test methods in a test class in the order they were defined?

Consider this XML file:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestNG Ordering" verbose="10">
    <test name="01 - Test 01" preserve-order="true">
        <classes>
            <class name="runner.AutomationFlow"/>
        </classes>
    </test>
</suite>

There will be probably just one test class.

and this class:

package runner;

import org.testng.ITestContext;
import org.testng.annotations.Test;

public class AutomationFlow {

    @Test(description="01 -Test 01")
    public void test1(ITestContext context){
    }

    @Test(description="02 - Test 02")
    public void test2(ITestContext context){
    }
   
    @Test(description="04 - Test 04")
    public void test4(ITestContext context){
    }
   
    @Test(description="03 - Test 03")
    public void test3(ITestContext context){
    }
}

TestNG (5.14beta) does not consider any ordering:

[TestRunner] Found 4 applicable methods
[TestRunner] WILL BE RUN SEQUENTIALLY:
[TestRunner] WILL BE RUN IN RANDOM ORDER:
[TestRunner]   runner.AutomationFlow.test1(org.testng.ITestContext)
[TestRunner]       on instances
[TestRunner]      runner.AutomationFlow@3c9217
[TestRunner]   runner.AutomationFlow.test2(org.testng.ITestContext)
[TestRunner]       on instances
[TestRunner]      runner.AutomationFlow@3c9217
[TestRunner]   runner.AutomationFlow.test3(org.testng.ITestContext)
[TestRunner]       on instances
[TestRunner]      runner.AutomationFlow@3c9217
[TestRunner]   runner.AutomationFlow.test4(org.testng.ITestContext)
[TestRunner]       on instances
[TestRunner]      runner.AutomationFlow@3c9217
[TestRunner] ===
[Invoker 27692793] Invoking runner.AutomationFlow.test1
[Invoker 27692793] Invoking runner.AutomationFlow.test2
[Invoker 27692793] Invoking runner.AutomationFlow.test3
[Invoker 27692793] Invoking runner.AutomationFlow.test4

Excuse me if this is the same problem I reported a few weeks ago or if it's already been reported :)

FK

Cédric Beust ♔

unread,
Aug 18, 2010, 7:23:45 PM8/18/10
to testng...@googlegroups.com
On Wed, Aug 18, 2010 at 4:19 PM, Felipe Knorr Kuhn <fkn...@gmail.com> wrote:
Hello Cédric,

I have faced an ordering problem and I'm not sure it's related to the other threads commented recently.

Since @Test(sequential=true) has been deprecated

Quick correction: sequential has not been removed, it's been renamed "singleThreaded" to clear some confusion. This attribute was never about running the test methods in a specific order, so hopefully, the new name captures its purpose better.

--
Cédric


Felipe Knorr Kuhn

unread,
Aug 18, 2010, 7:48:56 PM8/18/10
to testng...@googlegroups.com
Ah. I see.

So, the only way to keep the ordering will be using preserve-order=true in <test> and including every method?

FK

2010/8/18 Cédric Beust ♔ <ced...@beust.com>
--
Cédric


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Cédric Beust ♔

unread,
Aug 18, 2010, 7:59:15 PM8/18/10
to testng...@googlegroups.com
On Wed, Aug 18, 2010 at 4:48 PM, Felipe Knorr Kuhn <fkn...@gmail.com> wrote:
Ah. I see.

So, the only way to keep the ordering will be using preserve-order=true in <test> and including every method?

I'm afraid so. I can probably add some logic which, if preserve-order=true and no <methods> were specified in XML, will preserve the ordering of the methods returned from the reflection API, but as I said, it might still provide different orderings based on the JVM...

--
Cédric


Cédric Beust ♔

unread,
Aug 18, 2010, 7:25:36 PM8/18/10
to testng...@googlegroups.com
Sorry, posted too fast.


On Wed, Aug 18, 2010 at 4:19 PM, Felipe Knorr Kuhn <fkn...@gmail.com> wrote:
Since @Test(sequential=true) has been deprecated and preserve-order has been implemented, how would you tell the TestNG engine to execute the test methods in a test class in the order they were defined?

It's not really possible to do this at the Java level since different VM's will return the declared methods in different orders. You can't rely on reflection to give you this information, so right now, the only way you can do this is
  • Either by specifying these methods in your testng.xml file under the <class> tag.
  • Or by using dependencies in Java.
--
Cédric


Reply all
Reply to author
Forward
0 new messages