How to run Junit @Test methods in a proper order i.e prioritzing the @Test methods in Junit?

73 views
Skip to first unread message

Sudhansu Sekhar panda

unread,
Dec 24, 2014, 9:28:38 AM12/24/14
to seleniu...@googlegroups.com
Hi All,

How to prioritize Junit @Test methods...

Suppose i have five @Test  methods i want to run them either from top to botto or from bottom to top or in a given priority... Is there anyway i can do it in Junit?

e.g 

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
//@FixMethodOrder(MethodSorters.JVM)

public class CheckingJavaTestAnnotation {
@Test
public void ab(){
System.out.println("Sequence one");
}
@Test
public void abc(){
System.out.println("Sequence Two");
}
@Test
public void d(){
System.out.println("Sequence Three");
}
@Test
public void ef(){
System.out.println("Sequence Four");
}
@Test
public void g(){
System.out.println("Sequence five");
}
@Test
public void as(){
System.out.println("Sequence six");
}

output: 

Sequence one
Sequence Two
Sequence six
Sequence Three
Sequence Four
Sequence five

Thanks,

Sudhansu

pranab singh

unread,
Dec 24, 2014, 9:32:17 AM12/24/14
to seleniu...@googlegroups.com

Use the priority like
@Test(priority=0) like wise give the same according to ur order how u want.n remember negative will alys take the highest priority.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a7d69731-330e-4921-bf0a-bbd9815ed34e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sudhansu Sekhar panda

unread,
Dec 24, 2014, 11:48:51 PM12/24/14
to seleniu...@googlegroups.com
Hi Pranab,

It is showing error message as priority is not the recognized command for Junit...Can you please tell me which thing i need to import to get the error fixed?

Currently i am using import org.junit.Test;

Thanks,
Sudhansu 

pranab singh

unread,
Dec 25, 2014, 12:16:37 AM12/25/14
to seleniu...@googlegroups.com

Use can try with testng which is inspired from junit itself... And just try and let us know..

Sudhansu Sekhar panda

unread,
Dec 25, 2014, 12:17:16 AM12/25/14
to seleniu...@googlegroups.com
I am able to do using TestNG but i want to do using JUnit .....

Krishnan Mahadevan

unread,
Dec 25, 2014, 2:15:00 AM12/25/14
to Selenium Users

What has this question got to do with selenium ?
Have you tried posting this on a relevant JUnit forum ?

Reply all
Reply to author
Forward
0 new messages