TestNG Tutorials 18: Default Priority Of @Test Methods In TestNG

Hello Folks,

Let’s run below TestNG class and observe output:

Output:

Can you see different order of execution of test methods than it has appeared in class? “Amrrod” method is last but got executed first. “Print” method is first but executed in second position.

Actually, TestNG does not run Test methods as it appears in TestNG class (Until we use some attributes like priority etc). It sorts method names based on ASCII value of method name char by char in a method name and arrange them in ascending order. You can find ASCII value of Unicode characters here. ASCII values of “a”, “p” and “s” are “61”, “70”, and “73”. So order will be “amrrod”, “print” and “show” methods.

Let’s see some more:

We can define a method name starting with underscore(“_”) or dollar (“$”) or both. Examples are:

_Method , $Method, _$Method, $_Method 

How TestNG will priorities these method? It follows below rule based on ASCII value.

  1. ‘$’ has highest priority.
  2. Capital alphabets will be second priority.
  3. Underscore will have third priority.
  4. Small letter alphabets will be fourth priority.

See an example below:

Output:

 

Liked the post? If yes please share and let others also learn.

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappySelenium

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning