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

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...