top of page

How to use Skip Exception Test in TestNG

Using TestNG, we have multiple ways to execute our testcases. And there is a way to skip our test cases too from our execution. Today I am going to talk about the Skip Exception test in TestNG.

why do you need to skip a Testcase?

There are some certain conditions or reasons to skip a testcase

1. Unimplemented Testcases.

Working on Testcase and the test case is not yet completed still some more steps are required. In this condition, we can Specify attribute @Test(enabled=false), by using this annotation, the test case won't be executed.

2. Sometimes forcefully you want to skip some test cases which are not required for this time of execution or sprint. And We can Skip a test by using TestNG Skip Exception if we want to Skip a particular Test.

Syntax: throw new SkipException("message")

3. Based on certain conditions. If you want to implement the dependency of the test case execution, we can provide the condition. If the condition satisfies, the test case will be executed, else the test case will be skipped.

In This case the First test case “skipTest1” won’t be executed. Because it was not completed, and it won’t be available in Results of running class as well. You can see the below snippet.

Second test case “skipTest2”, we have skipped with throw exception. The test case returned the skip Exception as Shown in the snippet

The Third test case is based on the condition. From the above code snippet, we are passing the condition as false, so the test case will not be executed.

Total Execution summary:

Thanks for reading .. Happy learning!

498 views0 comments

Recent Posts

See All
bottom of page