Wednesday, July 4, 2018

How to enable or disable/ignore test methods in TestNG?

Sometimes we will be running into the situation where we need to disable/ignore some of the test cases or test methods from the execution because of various reasons like the test is failing due to known issue, the test data is not ready for the test and etc.

@Test annotation has many attributes, 'enabled' is the attribute used for disabling a test method. If we write @Test(enabled=false) for any test method in TestNG, then it will be ignored in the execution.

By default @Test() is enabled. @Test() is equivalent to @Test(enabled=true). Let us see an example on this to understand it better.


In the below java class, we have three test methods:
  • TestCase1 without 'enabled' attribute
  • TestCase2 with 'enabled' attribute as false
  • TestCase3 with 'enabled' attribute as true 

When we execute this test methods, only TestCase1 and TestCase3 will be executed and TestCase2 will be ignored from the execution. Please check the results screenshot below:


To enable a disabled test method either we should change 'enabled=true' or remove the attribute completely from the test method.

This is how we enable or disable the test methods in TestNG.

Thanks for reading. #qababu.com #HappyLearning #HappyTesting

No comments:

Post a Comment

Katalon 08: Integration of HP ALM with Katalon Studio

In this post, this post we discuss about integration of  HP ALM with Katalon Studio. If we can integrate HP ALM with Katalon we can update ...