How to use Regex.toTestFilter method of io.kotest.engine.test.status.SystemPropertyTestFilterEnabledExtension class

Best Kotest code snippet using io.kotest.engine.test.status.SystemPropertyTestFilterEnabledExtension.Regex.toTestFilter

SystemPropertyTestFilterEnabledExtension.kt

Source:SystemPropertyTestFilterEnabledExtension.kt Github

copy

Full Screen

1package io.kotest.engine.test.status2import io.kotest.core.descriptors.Descriptor3import io.kotest.core.filter.TestFilter4import io.kotest.core.filter.TestFilterResult5import io.kotest.core.internal.KotestEngineProperties6import io.kotest.core.test.Enabled7import io.kotest.core.test.TestCase8import io.kotest.mpp.Logger9import io.kotest.mpp.syspropOrEnv10/**11 * Applies test and spec filters using sysprop or env vars from [KotestEngineProperties.filterTests]12 * and [KotestEngineProperties.filterSpecs].13 *14 * These work similarly to gradle filters in --tests described at:15 * https://docs.gradle.org/current/userguide/java_testing.html#full_qualified_name_pattern16 */17internal object SystemPropertyTestFilterEnabledExtension : TestEnabledExtension {18 private val logger = Logger(SystemPropertyTestFilterEnabledExtension::class)19 override fun isEnabled(testCase: TestCase): Enabled {20 val filter = syspropOrEnv(KotestEngineProperties.filterTests) ?: ""21 logger.log { Pair(testCase.name.testName, "Filter tests syspropOrEnv=$filter") }22 val excluded = filter23 .propertyToRegexes()24 .map { it.toTestFilter().filter(testCase.descriptor) }25 .filterIsInstance<TestFilterResult.Exclude>()26 .firstOrNull()27 logger.log { Pair(testCase.name.testName, "excluded = $excluded") }28 return if (excluded == null) Enabled.enabled else Enabled.disabled(excluded.reason)29 }30}31private fun Regex.toTestFilter(): TestFilter = object : TestFilter {32 override fun filter(descriptor: Descriptor): TestFilterResult {33 val name = descriptor.path(false).value34 return if (this@toTestFilter.matches(name))35 TestFilterResult.Include36 else37 TestFilterResult.Exclude("Excluded by kotest.filter.tests test filter: ${this@toTestFilter}")38 }39}40private fun String.propertyToRegexes(): List<Regex> =41 this.split(",")42 .filter { it.isNotBlank() }43 .map { it.replace("*", ".*?").toRegex() }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in SystemPropertyTestFilterEnabledExtension

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful