Ignoring any test is a vital part of our test execution. Sometimes we may want to test only a specific sample of test cases and not all in order to save time thus our Goto approach would be to ignore particular test cases.
- It helps us save time.
- We can avoid testing if we already know whether it has any errors or not.
- Helps us to test on a priority basis thus saving us an ample amount of time.
- Helps in better reporting in case of any failure with the help of HTML reports, and extent reports.
- Download Eclipse IDE.
- Create a maven project in Eclipse.
- Add various dependencies like Selenium, TestNG, and WebDriver Manager.
- Download and install TestNG from the Eclipse marketplace.
In the first step, we would be creating a maven project inside Eclipse.
We would fill in basic details like name, group id, description, etc.
In the Second step, we would be adding a package and then create an execution file.
After creating the package, we would be creating different classes each performing different sets of actions as shown below.
Post creating the package we would be creating two separate Test Files as shown below:
Post creating this our file structure would be as shown below:
Since our initial aim is to understand how Ignoring any test case works in TestNG we would be using simple print statements to understand. We have two test Cases as shown below:
The output of the execution would be:
Now suppose we had to ignore test 2 and test 4 respectively, then we can achieve this task in two ways as shown below.
By using @Test (enabled = false) method:
We can see how for Test case 2 and test case 4 we have added the enabled method beside @test.
The resulting output is as shown below:
We clearly see that test cases 2, and 4 are skipped while executing.
We can achieve this in another way too as shown below.
We notice that in test case 5 of line no 12, above @test method we have added @Ignore.
This will ignore the given test case.
We notice that Test 5 is ignored.
In a similar fashion, we can ignore at the class level too by adding @ignore method at class level as shown below.
Running the above test, an entire class of NewTest1 would be ignored and only Test 2 would be executed as shown below.
Only the second Test would run because we have ignored the first test class in our above test.