Skip Test in TestNG

Skip test means, we don’t want to execute some particular test when Test Class will execute. In TestNG, we have various way to do this. We can skip the test completely or skip when some particular condition occurs.

 

There are many ways to skip the Test in TestNG, We will discuss all in detail with examples. Let’s see How we can skip the Tests in TestNG –

 

1. Using enabled = false – In TestNG, If your test case is not ready to use or you want to skip the test then you just need to use enable = false with @Test annotations.

Syntax –    @Test(enable = false)

 

2. Using SkipException()  – Another way to skip the Test in SkipException(). You just need to add SKipException() statement in your test case what you want to skip and the Test will be skipped at Runtime.

Syntax – throw new SkipException (“Declare Reason”);

 

Video Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

 

Let’s understand this all with the example.

 

Let’s see the Report. We are displaying TestNG console report here. You can also see these reports in your HTML reports.

Skip Test in TestNG

 

Have you noticed, We declared 5 tests in our Test Class and skipped 3 tests but in a report the count is one less.  secondTest() is not in our report neither in Executed nor in skipped. Why ? It because we skipped that test with

enabled = false .

 

That’s the disadvantage of enabled=false skip tests will not be reported in Report file. That’s why SkipExecption() is recommended to use.

0 Comment

Leave a Reply