I have 3 classes for with 3 tests each.
Class 1
@Test( priority = 1 )
public void testA1() {
System.out.println("testA1");
}
@Test( priority = 2 )
public void testA2() {
System.out.println("testA2");
}
@Test( priority = 3 )
public void testA3() {
System.out.println("testA3");
}
Class 2
@Test( priority = 1 )
public void testB1() {
System.out.println("testB1");
}
@Test( priority = 2 )
public void testB2() {
System.out.println("testB2");
}
@Test( priority = 3 )
public void testB3() {
System.out.println("testB3");
}
Class 3
@Test( priority = 1 )
public void testC1() {
System.out.println("testC1");
}
@Test( priority = 2 )
public void testC2() {
System.out.println("testC2");
}
@Test( priority = 3 )
public void testC3() {
System.out.println("testC3");
}
This is my XML file code.
<test verbose="2" name="hello" group-by-instances="true">
<classes>
<class name="Class1"></class>
<class name="Class2"></class>
<class name="Class3"></class>
</classes>
</test>
Here is my Answer testA1 testB1 testC1 testA2 testB2 testC2 testA3 testB3 testC3
But my expected answer is testA1 testA2 testA3 testB1 testB2 testB3 testC1 testC2 testC3
Thanks in advance for any help on this.
As you probably noticed, priority flag affect for whole not for single class. The easiest way is to jus increase priority level in second class.
Also you can put single class in single , i think it's even better if you want to separate tests domain.
And
verbose
flag. I hardly recommend this during debugging.The seen behavior is the expected one.
In fact,
priority
is more important thatgroup-by-instances
( https://github.com/cbeust/testng/blob/master/CHANGES.txt#L48) and that's why TestNG respectpriority
instead ofgroup-by-instances
.To achieve your expected behavior, you have to replace
priority
by a more important order feature, likedependsOnMethods
:As asked in the comments, if you really want a "priority on a class without a strong dependency", you can make it yourself with a method interceptor where you can order methods as you want. In pseudo code, something like:
Finally I got solution of problem.
Please refer below XML code for same.
This will give you expected result. Plus it will be easier to manage also. As if we want to see my all tests or remove some tests, i can look into test.xml