Skip to main content
Version: legacy

Skip Test Cases

In this article, we demonstrate how to skip test cases in a test suite by preconfiguring a Test Listener with the TestCaseContext.skipThisTestCase() method. To learn more about the usage of Test Listeners, go to Test Listeners (Test Hooks).

Skip Test Cases

  1. In the Test Explorer panel, right-click on Test Listeners. Select New > New Test Listener.

    Create a new test listener

  2. A New Test Listener dialog opens. Give it a name, such as Skiptest. Choose Generate sample Before Test Case method. Click OK.

    Name new test listener

    Katalon Studio generates a sample template with the necessary annotations, libraries and supported functions as below:

    import internal.GlobalVariable as GlobalVariable

    import com.kms.katalon.core.annotation.BeforeTestCase
    import com.kms.katalon.core.annotation.BeforeTestSuite
    import com.kms.katalon.core.annotation.AfterTestCase
    import com.kms.katalon.core.annotation.AfterTestSuite
    import com.kms.katalon.core.context.TestCaseContext
    import com.kms.katalon.core.context.TestSuiteContext

    class Skiptest {
    /**
    * Executes before every test case starts.
    * @param testCaseContext related information of the executed test case.
    */
    @BeforeTestCase
    def sampleBeforeTestCase(TestCaseContext testCaseContext) {
    println testCaseContext.getTestCaseId()
    println testCaseContext.getTestCaseVariables()
    }
  3. Use the TestCaseContext.skipThisTestCase() method to skip test cases. See also: skipThisTestCase()

    Inside the Skiptest Listener, copy and paste the following code under the generated sample template.

    // To check for the desired condition and skip the test case if true.
    if(inputyourconditionhere)
    { testCaseContext.skipThisTestCase()
    }
  4. Return to your test suite and run it. Check the results in the Results tab to see the final status of your tests.
Note:

Katalon Studio supports exporting test reports inHTML, CSV, PDFand JUnit. You can learn more about exporting reports here: Generate reports.

Example

In this example, we want to skip the Test Case named: "Google" in a test suite. We input the following sample code in the Skiptest Listener:

class Skiptest {
/**
* Executes before every test case starts.
* @param testCaseContext related information of the executed test case.
*/
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
println testCaseContext.getTestCaseId()
println testCaseContext.getTestCaseVariables()
if ((testCaseContext.getTestCaseId()) == "Test Cases/Google")
{ testCaseContext.skipThisTestCase()
}
}

Check the results after running the Test Suite. Katalon successfully skips the test case named: "Google".

Results after skipping test case