Last updated on June 10th, 2018 at 09:09 am
Let’s run below TestNG class and observe 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.
- ‘$’ has highest priority.
- Capital alphabets will be second priority.
- Underscore will have third priority.
- Small letter alphabets will be fourth priority.
See an example below:
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.
Author: Amod Mahajan
My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through 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