How to use loadSelectedSpecs method of io.kotest.framework.discovery.DiscoveryResult class

Best Kotest code snippet using io.kotest.framework.discovery.DiscoveryResult.loadSelectedSpecs

Discovery.kt

Source:Discovery.kt Github

copy

Full Screen

...78 private fun ClassInfo.load(init: Boolean): KClass<out Any> =79 Class.forName(name, init, this::class.java.classLoader).kotlin80 private fun doDiscovery(request: DiscoveryRequest): Result<DiscoveryResult> = runCatching {81 val specClasses =82 if (request.onlySelectsSingleClasses()) loadSelectedSpecs(request) else fromClassPaths83 val filtered = specClasses84 .asSequence()85 .filter(selectorFn(request.selectors))86 .filter(filterFn(request.filters))87 // all classes must subclass one of the spec parents88 .filter(isSpecSubclassKt)89 // we don't want abstract classes90 .filterNot(isAbstract)91 .toList()92 log { "After filters there are ${filtered.size} spec classes" }93 log { "[Discovery] Further filtering classes via discovery extensions [$discoveryExtensions]" }94 val afterExtensions = discoveryExtensions95 .fold(filtered) { cl, ext -> ext.afterScan(cl) }96 .sortedBy { it.simpleName }97 log { "After discovery extensions there are ${afterExtensions.size} spec classes" }98 val scriptsEnabled = System.getProperty(KotestEngineProperties.scriptsEnabled) == "true" ||99 System.getenv(KotestEngineProperties.scriptsEnabled) == "true"100// val scripts = when {101// scriptsEnabled -> discoverScripts()102// else -> emptyList()103// }104 if (scanResult.isInitialized()) runCatching { scanResult.value.close() }105 log { "Discovery result [${afterExtensions.size} specs; scripts]" }106 DiscoveryResult(afterExtensions, emptyList(), null)107 }108 /**109 * Returns whether this is a request that selects single classes110 * only. Used to avoid full classpath scans when not necessary.111 */112 private fun DiscoveryRequest.onlySelectsSingleClasses(): Boolean =113 selectors.isNotEmpty() &&114 selectors.all { it is DiscoverySelector.ClassDiscoverySelector }115 /**116 * Returns a list of [Spec] classes from discovery requests that only have117 * selectors of type [DiscoverySelector.ClassDiscoverySelector].118 */119 private fun loadSelectedSpecs(request: DiscoveryRequest): List<KClass<out Spec>> {120 log { "Discovery: Loading specified classes..." }121 val start = System.currentTimeMillis()122 // first filter down to spec instances only, then load the full class123 val loadedClasses = request124 .selectors125 .asSequence()126 .filterIsInstance<DiscoverySelector.ClassDiscoverySelector>()127 .map { Class.forName(it.className, false, this::class.java.classLoader) }128 .filter(isSpecSubclass)129 .map { Class.forName(it.name).kotlin }130 .filterIsInstance<KClass<out Spec>>()131 .toList()132 val duration = System.currentTimeMillis() - start133 log { "Discovery: Loading of selected classes completed in ${duration}ms" }...

Full Screen

Full Screen

loadSelectedSpecs

Using AI Code Generation

copy

Full Screen

1val discoveryResult = DiscoveryResult()2discoveryResult.loadSelectedSpecs(listOf("io.kotest.samples.FunSpecExample"))3val discoveryResult = DiscoveryResult()4discoveryResult.loadSelectedSpecs(listOf("io.kotest.samples.FunSpecExample"))5discoveryResult.loadSelectedSpecs(listOf("io.kotest.samples.FunSpecExample"))6.forEach { spec ->7spec.execute()8}9Configuration.addListener(MyListener())10Configuration.addListener(PrintSpecFailureListener)

Full Screen

Full Screen

loadSelectedSpecs

Using AI Code Generation

copy

Full Screen

1val discoveryResult = DiscoveryResult.loadSelectedSpecs(listOf("MySpec"))2discoveryResult.execute()3discoveryResult.execute(TestEngineListener)4discoveryResult.execute(TestEngineListener, TestEngineConfig)5discoveryResult.execute(TestEngineListener, TestEngineConfig, TestResultListener)6discoveryResult.execute(TestEngineListener, TestEngineConfig, TestResultListener, TestEngineLauncher)7discoveryResult.execute(TestEngineListener, TestEngineConfig, TestResultListener, TestEngineLauncher, TestEngineLauncherConfig)8discoveryResult.execute(TestEngineListener, TestEngineConfig, TestResultListener, TestEngineLauncher, TestEngineLauncherConfig, TestEngineListenerConfig)9discoveryResult.execute(TestEngineListener, TestEngineConfig, TestResultListener, TestEngineLauncher, TestEngineLauncherConfig, TestEngineListenerConfig, TestEngineListenerConfig)

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful