How to use pattern method of io.kotest.runner.junit.platform.gradle.GradlePostDiscoveryFilterExtractor class

Best Kotest code snippet using io.kotest.runner.junit.platform.gradle.GradlePostDiscoveryFilterExtractor.pattern


Source:KotestJunitPlatformTestEngine.kt Github


Full Screen

...74 * Classname.method: adds classname selector and ClassMethodNameFilter post discovery filter75 * org.Classname: doesn't seem to invoke the discover or execute methods.76 *77 * filter in gradle test block:78 * includeTestsMatching("*Test") - class selectors and ClassMethodNameFilter with pattern79 * includeTestsMatching("*Test") AND includeTestsMatching("org.gradle.internal.*") - class selectors and ClassMethodNameFilter with two patterns80 */81 override fun discover(82 request: EngineDiscoveryRequest,83 uniqueId: UniqueId,84 ): KotestEngineDescriptor {85 logger.log { Pair(null, "JUnit discovery request [uniqueId=$uniqueId]") }86 logger.log { Pair(null, request.string()) }87 // if we are excluded from the engines then we say goodnight according to junit rules88 val isKotest = request.engineFilters().all { it.toPredicate().test(this) }89 if (!isKotest)90 return KotestEngineDescriptor(uniqueId, emptyList(), emptyList(), emptyList(), null)91 val classMethodFilterRegexes = GradlePostDiscoveryFilterExtractor.extract(request.postFilters())92 val gradleClassMethodTestFilter = GradleClassMethodRegexTestFilter(classMethodFilterRegexes)93 // a method selector is passed by intellij to run just a single method inside a test file...

Full Screen

Full Screen


Source:GradlePostDiscoveryFilterExtractor.kt Github


Full Screen

...10 * But ClassMethodNameFilter, as the name implies, only handles clases and methods.11 * Kotest is more advanced, and JUnit5 Platform allows for hierarchical tests, so this is a limitation12 * of Gradle not implementing the spec fully.13 *14 * Since ClassMethodNameFilter is private, we can't get access to the underlying patterns, so we resort15 * to this reflection bullshit to get the raw strings out, so we can parse and apply the patterns ourselves,16 * thus allowing kotest to properly support the --tests options.17 *18 */19object GradlePostDiscoveryFilterExtractor {20 private val logger = Logger(GradlePostDiscoveryFilterExtractor::class)21 fun extract(filters: List<PostDiscoveryFilter>): List<String> {22 val classMethodFilters = filters.filter { it.javaClass.simpleName == "ClassMethodNameFilter" }23 return classMethodFilters.flatMap { extract(it) }24 }25 private fun extract(filter: Any): List<String> = runCatching {26 val matcher = testMatcher(filter)27 logger.log { Pair(null, "TestMatcher [$matcher]") }28 val commandLineIncludePatterns = commandLineIncludePatterns(matcher)29 logger.log { Pair(null, "commandLineIncludePatterns [$commandLineIncludePatterns]") }30 val regexes = { pattern(it) }31 logger.log { Pair(null, "ClassMethodNameFilter regexes [$regexes]") }32 regexes33 }.getOrElse { emptyList() }34 private fun testMatcher(obj: Any): Any {35 val field ="matcher")36 field.isAccessible = true37 return field.get(obj)38 }39 private fun commandLineIncludePatterns(obj: Any): List<Any> {40 val field ="commandLineIncludePatterns")41 field.isAccessible = true42 return field.get(obj) as List<Any>43 }44 private fun pattern(obj: Any): String {45 val field ="pattern")46 field.isAccessible = true47 val pattern: Pattern = field.get(obj) as Pattern48 return pattern.pattern()49 }50}...

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:


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 GradlePostDiscoveryFilterExtractor

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?