How to Fail/Skip a test case based on one or more validations

Objective: I want to perform few validations (checks) for each test case on test case variables and stop it from executing with proper error message in logs, IF any of the validations fails.

Current Implementation: Right now, I’m using ‘BeforeTestCase’ listener, ‘TestCaseContext.getTestCaseVariables()’ and ‘KeywordUtil.markFailedAndStop’ to perform checks in before test case and mark it as failed; however, this does not allow me to fail/skip the test case. Even if BeforetestCase fails, respective test case executes anyway.

Expected Solution: Some way to perform validations for a given test case using its context and fail/skip it if given condition(s) are not fulfilled.

I’ve thought of below ways so far, but don’t know how to implement it.
Is there a way, I can pass an instance of TestCaseContext for current test case in a custom keyword? Just the way we have in Listeners and then use it to validate variables.

You can use testCaseContext.skipThisTestCase() to skip the TestCase

Thanks HeleneB!
The test case is now skipped and status is set to ‘SKIPPED’
This works for me.