Best Kotest code snippet using io.kotest.engine.spec.resolveConfig.Long.toMillis
resolveConfig.kt
Source:resolveConfig.kt
1package io.kotest.engine.spec2import io.kotest.core.config.ProjectConfiguration3import io.kotest.core.spec.Spec4import io.kotest.core.test.Enabled5import io.kotest.core.test.EnabledOrReasonIf6import io.kotest.core.test.TestCase7import io.kotest.core.test.config.ResolvedTestConfig8import io.kotest.core.test.config.UnresolvedTestConfig9import io.kotest.engine.tags.tags10import kotlin.time.Duration11/**12 * Accepts an [UnresolvedTestConfig] and returns a [ResolvedTestConfig] by completing13 * any nulls in the unresolved config with defaults from the [spec] or [ProjectConfiguration].14 */15internal fun resolveConfig(16 config: UnresolvedTestConfig?,17 xdisabled: Boolean?,18 parent: TestCase?,19 spec:Spec,20 configuration: ProjectConfiguration21): ResolvedTestConfig {22 val defaultTestConfig = spec.defaultTestConfig23 ?: spec.defaultTestCaseConfig()24 ?: configuration.defaultTestConfig25 val enabled: EnabledOrReasonIf = { testCase ->26 when {27 // if xdisabled we always override any other enabled/disabled flags28 xdisabled == true -> Enabled.disabled("Disabled by xmethod")29 config?.enabled == false -> Enabled.disabled("Disabled by enabled flag in config")30 config?.enabledIf != null -> if (config.enabledIf!!.invoke(testCase)) Enabled.enabled else Enabled.disabled("Disabled by enabledIf flag in config")31 config?.enabledOrReasonIf != null -> config.enabledOrReasonIf!!.invoke(testCase)32 !defaultTestConfig.enabled -> Enabled.disabled33 !defaultTestConfig.enabledIf.invoke(testCase) -> Enabled.disabled34 else -> defaultTestConfig.enabledOrReasonIf.invoke(testCase)35 }36 }37 val timeout: Duration? = config?.timeout38 ?: parent?.config?.timeout39 ?: spec.timeout?.toMillis()40 ?: spec.timeout()?.toMillis()41 ?: defaultTestConfig.timeout42 ?: configuration.timeout?.toMillis()43 val threads = config?.threads44 ?: spec.threads45 ?: spec.threads()46 ?: defaultTestConfig.threads47 val invocations = config?.invocations48 ?: defaultTestConfig.invocations49 val invocationTimeout: Duration? = config?.invocationTimeout50 ?: parent?.config?.invocationTimeout51 ?: spec.invocationTimeout?.toMillis()52 ?: spec.invocationTimeout()?.toMillis()53 ?: defaultTestConfig.invocationTimeout54 ?: configuration.invocationTimeout?.toMillis()55 val extensions = (config?.listeners ?: emptyList()) +56 (config?.extensions ?: emptyList()) +57 defaultTestConfig.extensions +58 defaultTestConfig.listeners59 return ResolvedTestConfig(60 enabled = enabled,61 threads = threads,62 invocations = invocations,63 timeout = timeout,64 invocationTimeout = invocationTimeout,65 tags = (config?.tags ?: emptySet()) + (defaultTestConfig.tags) + (parent?.config?.tags ?: emptySet()) + spec.tags() + spec.appliedTags() + spec::class.tags(),66 extensions = extensions,67 failfast = config?.failfast ?: parent?.config?.failfast ?: spec.failfast ?: configuration.failfast,68 severity = config?.severity ?: parent?.config?.severity ?: spec.severity ?: configuration.severity,69 assertSoftly = config?.assertSoftly ?: parent?.config?.assertSoftly ?:spec.assertSoftly ?: configuration.globalAssertSoftly,70 assertionMode = config?.assertionMode ?: parent?.config?.assertionMode ?: spec.assertions ?: spec.assertionMode() ?: configuration.assertionMode,71 coroutineDebugProbes = config?.coroutineDebugProbes ?: parent?.config?.coroutineDebugProbes ?:spec.coroutineDebugProbes ?: configuration.coroutineDebugProbes,72 testCoroutineDispatcher = config?.testCoroutineDispatcher ?: parent?.config?.testCoroutineDispatcher ?: spec.testCoroutineDispatcher ?: configuration.testCoroutineDispatcher,73 coroutineTestScope = config?.coroutineTestScope ?: parent?.config?.coroutineTestScope ?: spec.coroutineTestScope ?: configuration.coroutineTestScope,74 blockingTest = config?.blockingTest ?: parent?.config?.blockingTest ?: spec.blockingTest ?: configuration.blockingTest,75 )76}77fun Long.toMillis(): Duration = Duration.milliseconds(this)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!