top of page

TestNG @Test attributes

  1. description: a string that gives information about the test it is attached to.

  2. timeOut: this is the maximum number of milliseconds for a test run. When a test run exceeds the specified timeOut, it will throw an org.testng.internal.thread.ThreadTimeoutException: "Method org.testng.internal.TestNGMethod.methodName() didn't finish within the time-out numberOfSeconds". This is very useful when tests remain stuck, especially if you run them from a continuous delivery system, preventing the whole test suite that runs from being stuck indefinitely.

  3. priority: when this attribute is not declared in your tests, the order in which the test methods are run when selecting to run all the tests in your class is random. For clarity, many times you would like to run some tests after others. That's where 'priority' steps in. It can hold integer values between -5000 and 5000. The test with the lowest priority runs first, then the one with the next priority, and so on. For instance, if you have three tests, one having priority -5000, one with 0 and one with 10, the order in which they run is : -5000, 0, 10. The default priority, if none is specified, for all tests, is 0. Keep in mind that priority is different than dependency, hence the priority only specifies when to run a test, and tests are independent of each other.

  4. dependsOnMethods: when you want to run a test only after another test has run successfully, making the second test's run dependent on the first test's successful outcome, you will specify this attribute. If the first test fails, the one dependent on it will not run.

  5. enabled: this attribute has boolean values, and by default (when it is not specified), it is 'true'. This attribute is only worth specifying explicitly when you don't want a certain test method or class to be run, by setting the attribute to false. For example, if from your IDE you run the whole test class in which an 'enabled=false' method resides, this method will be skipped, while the others will be run.

  6. groups: this attribute is useful for grouping together tests that relate to the same functionality, are of the same importance or are of the same type. You can use groups from within TestNG to either include tests having a particular group in a run, or to exclude them. To learn how to user this functionality, please refer to:

An example of a @Test method, that contains all the above attributes:

@Test(description = "This a new test", timeOut = 20000, priority = -200, dependsOnMethods = "test1", groups ="tutorial")
public void test2(){

The next step is to actually run these tests, which you can learn how to do here:

Recent Posts

See All

Creating an Architecture for Your Automated Tests Writing Automated Tests in Small Increments 4 Times Your Automation Passed While Bugs Were Present Now That You’ve Created Automated Tests, Run Them!

This week my newest article was released, this time on how to use Log4j to log relevant test automation information:

bottom of page