TestNG Tutorials 26: Understand Usage of alwaysRun Attribute With Test Method of TestNG
Hello Folks,
In this post we will learn about “alwaysRun” attribute and its usage with @Test annotated method in TestNG.
“alwaysRun” attribute can be used with Configuration methods(BeforeXXXX and @AfterXXXX) and Test methods(@Test).
TestNG documentation defines alwaysRun attribute as:
For configuration methods:
For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not beforeGroups): If set to true, this configuration method will be run regardless of what groups it belongs to.
For after methods (afterSuite, afterClass, …): If set to true, this configuration method will be run even if one or more methods invoked previously failed or was skipped. Default value of alwaysRun attribute is false.
For Test methods:
If set to true, this test method will always be run even if it depends on a method that failed.
In this post, we will see usage of alwaysRun for Test methods. For configuration method see this post.
Let’s start with examples:
Suppose we have 2 test methods in a TestNG class as below:
On running above class as a TestNG suite, you will get below output: Method 1
Method 2