• Post Reply Bookmark Topic Watch Topic
  • New Topic

An Easier Way to Control Test Order in TestNG?

Joshua Tree
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I've seen a few similar questions posted but none that quite answered my question directly...
I'm using Selenium Webdriver 2.0 with TestNg and Java and I'm looking for a better way to control the order in which tests are run.
Really all I want is the tests cases to run in the order they're written in the classes.
It's intuitive. Its easy. Its maintainable. And I'm really surprised it's not the default for testNg.
(Why apply some random ordering when it's not explicitly requested by the coder?)

Anyway, I know that I can add a list of methods to my testng xml, but I have 130 tests so far (and several hundred to come!) and such a method list will be far too much for future maintenance.
EG when I add ten test methods I'll have to remember to add all those methods to my xml file. And what happens if I miss adding one? I'll never notice that it was never run...

So this solution would be a maintenance nightmare:

<test name="BVTQA01">
<class name="TestPackage.BVT">
<include name="testLogin"></include>
<include name="testAddToCart"></include>
<include name="test999 etc"></include>

I've also tried preserve-order:

<test name="BVTQA01" preserve-order="true">
<class name="TestPackage.TestBVT" />

but it's apparently ignored if I don't add a list of methods and the maintenance nightmare of 'include name' lists...

So currently I'm just listing my test classes in the xml file (as above- TestBVT which has 20 methods, etc.), and controlling test run order with 'depends on' annotations on the tests themselves.
However this is not ideal as I am creating dependencies on every method. And I want to remove the dependencies where they are not really necessary.
I only want to use 'depends on' when there is a real dependency.

I've also searched for creating the xml automatically from my @Test annotated methods. But the solutions posted are not clear on how to actually implement.

Any feedback on how to just make testNg run through my test classes from top to bottom, in order written, without any random sorting- or maintenance heavy list generation would be wonderful.
Thanks in advance,

Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!