Benefits, Hierarchy & Prioritization in TESTNG
Benefits Of TestNG Annotations
Let's talk about the benefits of TestNG Annotations.
• TestNG annotations help provide a thorough and complete
test report with information on the number of test cases executed, passed test
cases, failed test cases, and skipped test cases.
• The testing.xml file allows for simple grouping of many
test scenarios. Furthermore, test cases can be prioritised for execution.
• Using the keyword 'invocation count,' TestNG Annotations
can run the same test case many times.
• TestNG annotations are simple to comprehend.
• TestNG Annotations allow for simplified test code,
hence removing the need for a static primary method.
• TestNG facilitates the grouping and execution of test
cases.
• TestNG allows programmers to prioritise test cases
depending on their requirements.
• TestNG helps in the concurrent execution of test
cases.
• TestNG is an excellent tool for generating reports
based on test results.
• TestNG is strongly typed, indicating that it can do solid
error checking.
• TestNG has the ability to connect to external data
sources.
• There is no necessity to follow a pattern or format while
executing test cases.
• TestNG annotations can accept additional parameters.
• There is no necessity to extend any test classes when
using TestNG annotations.
• Because TestNG Annotations are highly typed,
errors can be detected at compile time.
Hierarchy of the
TestNG Annotations:
When you're testing software, TestNG offers a number of
annotations to assist you write good test source code. So, how does TestNG
determine which test case should be performed first, then the next, and so on?
The answer is a hierarchy in these annotations. As a result, the annotations in
testNG have a hierarchy. The following is the hierarchy (with the highest
priority at the top):
- @BeforeSuite
- @BeforeTest
- @BeforeClass
- @BeforeMethod
- @Test
- @AfterMethod
- @AfterClass
- @AfterTest
- @AfterSuite
TestNG
Prioritization
Prioritization in TestNG is a technique for assigning a
sequence to methods so that they don't run in the wrong order. Because TestNG's
alphabetically running test cases have no logical sequence, assigning priority
to these test cases helps us manage the execution of our tests.
Priority is a parameter in TestNG test cases that has a
distinctive value as a priority.
We can use the priority as an additional option with the
test annotations. This attribute defines the annotation's importance. However,
keep in mind that the priority check comes after TestNG's annotation check. As
a result, the TestNG annotation hierarchy comes first, followed by
priority-based execution.
In TestNG, the following points about priority must be taken
into account:
• In TestNG test methods, only @Test methods can be used to
define Priority.
• When the priority number is smaller, the test case method
has a greater priority.
• Only integer values are used in Priority in TestNG. The
value can be 0 (zero), a negative number, or a positive number.
• If a priority is expressed in decimal, it must first be
converted to an integer in TestNG (through typecasting).
• In TestNG, only one process is allowed to have a single
priority.
• Priority is not able to pass across XML files.
Comments
Post a Comment