Skipping test is also an important concept in TestNG. You can skip the test from running as you don’t want to Run the @test and mark the @test as Skip in reports.
To Skip the test we need to use org.testng.SkipException
an Exception Class from TestNG. We have to throw an exception to the first line and code will come out from the test. You can have a look at Java document to read more about exception throwing.
How to Skip @Test:
We are going to throw SkipException in the following example Class.
package com.tutorial.testng;
import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.Test;
public class SkipTestInTestng {
// Skip Test
@Test()
public void skipTestMethod() {
throw new SkipException("Skipped Test");
}
// Pass Test
@Test()
public void passTestMethod() {
Assert.assertTrue(true);
}
// Fail Test
@Test()
public void failTestMethod() {
Assert.assertTrue(false);
}
}
When You Run the Class:
When we ran the above example class TestNG report has one Test Failure and one Test marked as Skipped.
===============================================
Default test
Tests run: 3, Failures: 1, Skips: 1
===============================================