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

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

KotestJunitPlatformTestEngine.kt

Source: KotestJunitPlatformTestEngine.kt Github

copy

Full Screen

...8import io.kotest.engine.listener.ThreadSafeTestEngineListener9import io.kotest.framework.discovery.Discovery10import io.kotest.mpp.Logger11import io.kotest.runner.junit.platform.gradle.GradleClassMethodRegexTestFilter12import io.kotest.runner.junit.platform.gradle.GradlePostDiscoveryFilterExtractor13import org.junit.platform.engine.DiscoverySelector14import org.junit.platform.engine.EngineDiscoveryRequest15import org.junit.platform.engine.ExecutionRequest16import org.junit.platform.engine.TestEngine17import org.junit.platform.engine.TestExecutionResult18import org.junit.platform.engine.UniqueId19import org.junit.platform.engine.discovery.MethodSelector20import org.junit.platform.engine.discovery.UniqueIdSelector21import org.junit.platform.engine.support.descriptor.EngineDescriptor22import org.junit.platform.launcher.LauncherDiscoveryRequest23import java.util.*24import kotlin.reflect.KClass25/​**26 * A Kotest implementation of a Junit Platform [TestEngine].27 */​28class KotestJunitPlatformTestEngine : TestEngine {29 private val logger = Logger(KotestJunitPlatformTestEngine::class)30 companion object {31 const val EngineId = "kotest"32 }33 override fun getId(): String = EngineId34 override fun getGroupId(): Optional<String> = Optional.of("io.kotest")35 override fun execute(request: ExecutionRequest) {36 logger.log { Pair(null, "ExecutionRequest[${request::class.java.name}] [configurationParameters=${request.configurationParameters}; rootTestDescriptor=${request.rootTestDescriptor}]") }37 val root = request.rootTestDescriptor as KotestEngineDescriptor38 when (root.error) {39 null -> execute(request, root)40 else -> abortExecution(request, root.error)41 }42 }43 private fun abortExecution(request: ExecutionRequest, e: Throwable) {44 request.engineExecutionListener.executionStarted(request.rootTestDescriptor)45 request.engineExecutionListener.executionFinished(request.rootTestDescriptor, TestExecutionResult.failed(e))46 }47 private fun execute(request: ExecutionRequest, root: KotestEngineDescriptor) {48 val configuration = ProjectConfiguration()49 val listener = ThreadSafeTestEngineListener(50 PinnedSpecTestEngineListener(51 JUnitTestEngineListener(52 SynchronizedEngineExecutionListener(53 request.engineExecutionListener54 ),55 root,56 )57 )58 )59 request.configurationParameters.get("kotest.extensions").orElseGet { "" }60 .split(',')61 .map { it.trim() }62 .filter { it.isNotBlank() }63 .map { Class.forName(it).newInstance() as Extension }64 .forEach { configuration.registry.add(it) }65 TestEngineLauncher(listener)66 .withConfiguration(configuration)67 .withExtensions(root.testFilters)68 .withClasses(root.classes)69 .launch()70 }71 /​**72 * gradlew --tests rules:73 * Classname: adds classname selector and ClassMethodNameFilter post discovery filter74 * 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 file94 /​/​ this happens for example, when trying to run a junit test alongside kotest tests,95 /​/​ and kotest will then run all other tests.96 /​/​ Some other engines run tests via uniqueId selectors97 /​/​ therefore, the presence of a MethodSelector or a UniqueIdSelector means we must run no tests in KT.98 /​/​ if we get a uniqueid with kotest as engine we throw because that should never happen99 val allSelectors = request.getSelectorsByType(DiscoverySelector::class.java)100 val containsUnsupported = allSelectors.any {101 if (it is UniqueIdSelector)102 if (it.uniqueId.engineId.get() == EngineId)103 throw RuntimeException("Kotest does not allow running tests via uniqueId")104 else true105 else...

Full Screen

Full Screen

GradlePostDiscoveryFilterExtractor.kt

Source: GradlePostDiscoveryFilterExtractor.kt Github

copy

Full Screen

...15 * 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 = commandLineIncludePatterns.map { pattern(it) }31 logger.log { Pair(null, "ClassMethodNameFilter regexes [$regexes]") }32 regexes33 }.getOrElse { emptyList() }34 private fun testMatcher(obj: Any): Any {...

Full Screen

Full Screen

GradlePostDiscoveryFilterExtractor

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.Spec2import io.kotest.runner.junit.platform.gradle.GradlePostDiscoveryFilterExtractor3import org.junit.platform.engine.discovery.DiscoverySelectors4import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder5import org.junit.platform.launcher.core.LauncherFactory6object GradlePostDiscoveryFilterExtractorTest {7 fun main(args: Array<String>) {8 val classes = listOf(9 val launcher = LauncherFactory.create()10 val request = LauncherDiscoveryRequestBuilder.request()11 .selectors(classes.map { DiscoverySelectors.selectClass(it) })12 .build()13 val filter = GradlePostDiscoveryFilterExtractor.extract(request, launcher)14 val filteredSpecs = filter.filter(classes.map { Class.forName(it).kotlin as Class<out Spec> })15 println(filteredSpecs)16 }17}18[kotlin.KotlinReflectionInternalError: Exception while analyzing expression at (1,1) in /​home/​ranjit/​IdeaProjects/​kotest/​kotest-runner/​kotest-runner-junit5/​src/​test/​kotlin/​io/​kotest/​runner/​junit5/​SpecExecutorTest.kt]

Full Screen

Full Screen

GradlePostDiscoveryFilterExtractor

Using AI Code Generation

copy

Full Screen

1val gradlePostDiscoveryFilterExtractor = GradlePostDiscoveryFilterExtractor(gradleTestFilter)2val kotestTestEngine = KotestTestEngine()3kotestTestEngine.execute(kotestTestFilter)4val gradleTestFilter = GradleTestFilter()5val gradlePostDiscoveryFilterExtractor = GradlePostDiscoveryFilterExtractor(gradleTestFilter)6val kotestTestEngine = KotestTestEngine()7kotestTestEngine.execute(kotestTestFilter)8val gradleTestFilter = GradleTestFilter()9val gradlePostDiscoveryFilterExtractor = GradlePostDiscoveryFilterExtractor(gradleTestFilter)10val kotestTestEngine = KotestTestEngine()11kotestTestEngine.execute(kotestTestFilter)12val gradleTestFilter = GradleTestFilter()13val gradlePostDiscoveryFilterExtractor = GradlePostDiscoveryFilterExtractor(gradleTestFilter)14val kotestTestEngine = KotestTestEngine()15kotestTestEngine.execute(kotestTestFilter)

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Test Optimization for Continuous Integration

“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.

Complete Guide To Styling Forms With CSS Accent Color

The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).

Test strategy and how to communicate it

I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

How To Find Hidden Elements In Selenium WebDriver With Java

Have you ever struggled with handling hidden elements while automating a web or mobile application? I was recently automating an eCommerce application. I struggled with handling hidden elements on the web page.

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 methods in GradlePostDiscoveryFilterExtractor

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful