Hi Cedric,
What do you mean by "dependencies in your classes" and how this could
effect ordering of test-cases.
I am looking at TestRunner.java where you segregate 'parallel and
Sequential' methods.I think this is the only
place where order is decided.
It's only in Db related test-cases ,i am having some problem.
Problem Statement : Let's say i am having 2 test - classes
[com.A,com.B]
Each Test class has a BeforeClass method which starts a Hibernate
Transaction.
So If one Test Class say com.B Starts Executing :
It will start a transaction and will have some modified Hibernate
Entities in Transaction.
Now even before AfterClass method of com.B is executed ,TestNG starts
new executing com.A methods.
Now we are having two Hibernate transaction's open modifying same data
in Db and hence i get stale Object exception
from Hibernate.
Note : This behavior is fine in application that it will throw stale
object Excpetion to User if more than one User modifies
simultaneously.
What I need : A Test Class Should execute all the methods between
BeforeClass and AfterClass before it starts executing another Test
Class BeforeClass method.
<!--------- Sample Code ----->
public class A{
@BeforeClass
public void beforeClass(){
System.err.println("Starting Hibernate Transaction for A");}
@AfterClass
public void afterClass(){
System.err.println("Commiting Hibernate Transaction for A");}
@Test(dependsOnMethods = "b")
public void a(){
printDetails( "A.a()" );}
@Test
public void b(){
printDetails( "A.b()" );}
@Test
public void c(){
printDetails( "A.c()" );}
@Test
public void d(){
printDetails( "A.d()" );}
private void printDetails(String methodName){
System.out.println( "Doing Some Db work in " + methodName );}
}
public class B{
@BeforeClass
public void beforeClass(){
System.err.println("Starting Hibernate Transaction for B");}
@AfterClass
public void afterClass(){
System.err.println("Commiting Hibernate Transaction for B");}
@Test(dependsOnMethods = "b")
public void a(){
printDetails( "B.a()" );}
@Test
public void b(){
printDetails( "B.b()" );}
@Test
public void c(){
printDetails( "B.c()" );}
@Test
public void d(){
printDetails( "B.d()" );}
private void printDetails(String methodName){
System.out.println( "Doing Some Db work in " + methodName );}
}
testng.xml:
<!DOCTYPE suite SYSTEM "
http://testng.org/testng-1.0.dtd">
<suite name="someSuit" >
<test verbose="2" name="com" >
<classes>
<class name="com.A"/>
<class name="com.B"/>
</classes>
</test>
</suite>
<!--------------------------------------------------------->
Output I get
Starting Hibernate Transaction for B
Doing Some Db work in B.b()
Starting Hibernate Transaction for A
Doing Some Db work in A.b()
Doing Some Db work in A.a()
Doing Some Db work in B.a()
Doing Some Db work in A.c()
Doing Some Db work in A.d()
Commiting Hibernate Transaction for A
Doing Some Db work in B.c()
Doing Some Db work in B.d()
Commiting Hibernate Transaction for B
> ***Cédric
> *