Best Kotest code snippet using io.kotest.engine.tags.runtime.ProjectConfiguration.runtimeTags
dump.kt
Source:dump.kt
1package io.kotest.engine.config2import io.kotest.core.config.ProjectConfiguration3import io.kotest.engine.tags.runtimeTags4import io.kotest.mpp.bestName5fun ProjectConfiguration.createConfigSummary(): String {6 val sb = StringBuilder()7 sb.buildOutput("Parallelization factor", parallelism.toString())8 sb.buildOutput("Concurrent specs", concurrentSpecs.toString())9 sb.buildOutput("Global concurrent tests", concurrentTests.toString())10 sb.buildOutput("Dispatcher affinity", dispatcherAffinity.toString())11 sb.buildOutput("Coroutine debug probe", coroutineDebugProbes.toString())12 sb.buildOutput("Spec execution order", specExecutionOrder.name)13 sb.buildOutput("Default test execution order", testCaseOrder.name)14 sb.buildOutput("Default test timeout", timeout.toString() + "ms")15 sb.buildOutput("Default test invocation timeout", invocationTimeout.toString() + "ms")16 if (projectTimeout != null)17 sb.buildOutput("Overall project timeout", projectTimeout.toString() + "ms")18 sb.buildOutput("Default isolation mode", isolationMode.name)19 sb.buildOutput("Global soft assertions", globalAssertSoftly.toString())20 sb.buildOutput("Write spec failure file", writeSpecFailureFile.toString())21 if (writeSpecFailureFile) {22 sb.buildOutput("Spec failure file path",23 specFailureFilePath.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() })24 }25 sb.buildOutput("Fail on ignored tests", failOnIgnoredTests.toString())26 sb.buildOutput("Fail on empty test suite", failOnEmptyTestSuite.toString())27 sb.buildOutput("Duplicate test name mode", duplicateTestNameMode.name)28 if (includeTestScopeAffixes != null)29 sb.buildOutput("Include test scope affixes", includeTestScopeAffixes.toString())30 sb.buildOutput("Remove test name whitespace", removeTestNameWhitespace.toString())31 sb.buildOutput("Append tags to test names", testNameAppendTags.toString())32 if (registry.isNotEmpty()) {33 sb.buildOutput("Extensions")34 registry.all().map(::mapClassName).forEach {35 sb.buildOutput(it, indentation = 1)36 }37 }38 runtimeTags().expression?.let { sb.buildOutput("Tags", it) }39 return sb.toString()40}41fun ProjectConfiguration.dumpProjectConfig() {42 println("~~~ Kotest Configuration ~~~")43 println(createConfigSummary())44}45private fun StringBuilder.buildOutput(key: String, value: String? = null, indentation: Int = 0) {46 if (indentation == 0) {47 append("-> ")48 } else {49 for (i in 0 until indentation) {50 append(" ")51 }52 append("- ")53 }54 append(key)55 value?.let { append(": $it") }56 append("\n")57}58private fun mapClassName(any: Any) = any::class.bestName()...
TestEngine.kt
Source:TestEngine.kt
1package io.kotest.engine2import io.kotest.common.ExperimentalKotest3import io.kotest.common.KotestInternal4import io.kotest.common.Platform5import io.kotest.common.platform6import io.kotest.core.TagExpression7import io.kotest.core.config.ProjectConfiguration8import io.kotest.core.project.TestSuite9import io.kotest.engine.interceptors.EngineContext10import io.kotest.engine.interceptors.EngineInterceptor11import io.kotest.engine.listener.TestEngineListener12import io.kotest.engine.tags.runtimeTags13import io.kotest.mpp.Logger14data class EngineResult(val errors: List<Throwable>) {15 companion object {16 val empty = EngineResult(emptyList())17 }18 fun addError(t: Throwable): EngineResult {19 return EngineResult(errors + t)20 }21}22@KotestInternal23data class TestEngineConfig(24 val listener: TestEngineListener,25 val interceptors: List<EngineInterceptor>,26 val configuration: ProjectConfiguration,27 val explicitTags: TagExpression?,28)29/**30 * Multiplatform Kotest Test Engine.31 */32@KotestInternal33class TestEngine(private val config: TestEngineConfig) {34 private val logger = Logger(this::class)35 /**36 * Starts execution of the given [TestSuite], intercepting calls via [EngineInterceptor]s.37 *38 * It is recommended that this method is not invoked, but instead the engine39 * is launched via the [TestEngineLauncher].40 */41 @OptIn(KotestInternal::class, ExperimentalKotest::class)42 internal suspend fun execute(suite: TestSuite): EngineResult {43 logger.log { Pair(null, "Executing test suite with ${suite.specs.size} specs") }44 val innerExecute: suspend (EngineContext) -> EngineResult = { context ->45 val scheduler = when (platform) {46 Platform.JVM -> ConcurrentTestSuiteScheduler(47 config.configuration.concurrentSpecs ?: config.configuration.parallelism,48 context,49 )50 Platform.JS -> SequentialTestSuiteScheduler(context)51 Platform.Native -> SequentialTestSuiteScheduler(context)52 }53 scheduler.schedule(context.suite)54 }55 logger.log { Pair(null, "${config.interceptors.size} engine interceptors") }56 val execute = config.interceptors.foldRight(innerExecute) { extension, next ->57 { context -> extension.intercept(context, next) }58 }59 val tags = config.configuration.runtimeTags()60 logger.log { Pair(null, "TestEngine: Active tags: ${tags.expression}") }61 return execute(EngineContext(suite, config.listener, tags, config.configuration))62 }63}...
RequiresTagSpecInterceptor.kt
Source:RequiresTagSpecInterceptor.kt
1package io.kotest.engine.spec.interceptor2import io.kotest.common.flatMap3import io.kotest.core.NamedTag4import io.kotest.core.annotation.RequiresTag5import io.kotest.core.annotation.requirestag.wrapper6import io.kotest.core.config.ProjectConfiguration7import io.kotest.core.config.ExtensionRegistry8import io.kotest.core.filter.SpecFilter9import io.kotest.core.spec.SpecRef10import io.kotest.core.test.TestCase11import io.kotest.core.test.TestResult12import io.kotest.engine.listener.TestEngineListener13import io.kotest.engine.spec.SpecExtensions14import io.kotest.engine.tags.isActive15import io.kotest.engine.tags.parse16import io.kotest.engine.tags.runtimeTags17import io.kotest.mpp.annotation18/**19 * A [SpecFilter] which will ignore specs if they are annotated with @[RequiresTag]20 * and those tags are not present in the runtime tags.21 */22internal class RequiresTagSpecInterceptor(23 private val listener: TestEngineListener,24 private val configuration: ProjectConfiguration,25 private val registry: ExtensionRegistry,26) : SpecRefInterceptor {27 override suspend fun intercept(28 ref: SpecRef,29 fn: suspend (SpecRef) -> Result<Map<TestCase, TestResult>>30 ): Result<Map<TestCase, TestResult>> {31 return when (val annotation = ref.kclass.annotation<RequiresTag>()) {32 null -> fn(ref)33 else -> {34 val requiredTags = annotation.wrapper.map { NamedTag(it) }.toSet()35 val expr = configuration.runtimeTags().parse()36 if (requiredTags.isEmpty() || expr.isActive(requiredTags)) {37 fn(ref)38 } else {39 runCatching { listener.specIgnored(ref.kclass, "Disabled by @RequiresTag") }40 .flatMap { SpecExtensions(registry).ignored(ref.kclass, "Disabled by @RequiresTag") }41 .map { emptyMap() }42 }43 }44 }45 }46}...
enabled.kt
Source:enabled.kt
1package io.kotest.engine.test.status2import io.kotest.core.config.ProjectConfiguration3import io.kotest.core.extensions.EnabledExtension4import io.kotest.core.test.Enabled5import io.kotest.core.test.TestCase6import io.kotest.engine.spec.SpecExtensions7import io.kotest.engine.tags.runtimeTags8/**9 * Returns [Enabled.enabled] if the given [TestCase] is enabled based on default rules10 * from [isEnabledInternal] or any registered [EnabledExtension]s.11 */12suspend fun TestCase.isEnabled(conf: ProjectConfiguration): Enabled {13 val internal = isEnabledInternal(conf)14 return if (!internal.isEnabled) {15 internal16 } else {17 val disabled = SpecExtensions(conf.registry)18 .extensions(spec)19 .filterIsInstance<EnabledExtension>()20 .map { it.isEnabled(descriptor) }21 .firstOrNull { it.isDisabled }22 disabled ?: Enabled.enabled23 }24}25/**26 * Determines enabled status by using [TestEnabledExtension]s.27 */28internal fun TestCase.isEnabledInternal(conf: ProjectConfiguration): Enabled {29 val extensions = listOf(30 TestConfigEnabledExtension,31 TagsEnabledExtension(conf.runtimeTags()),32 TestFilterEnabledExtension(conf.registry),33 SystemPropertyTestFilterEnabledExtension,34 FocusEnabledExtension,35 BangTestEnabledExtension,36 SeverityLevelEnabledExtension,37 )38 return extensions.fold(Enabled.enabled) { acc, ext -> if (acc.isEnabled) ext.isEnabled(this) else acc }39}...
TagsExcludedDiscoveryExtension.kt
Source:TagsExcludedDiscoveryExtension.kt
1package io.kotest.engine.spec.interceptor2import io.kotest.common.flatMap3import io.kotest.core.TagExpression4import io.kotest.core.config.ProjectConfiguration5import io.kotest.core.spec.Spec6import io.kotest.core.spec.SpecRef7import io.kotest.core.test.TestCase8import io.kotest.core.test.TestResult9import io.kotest.engine.listener.TestEngineListener10import io.kotest.engine.spec.SpecExtensions11import io.kotest.engine.tags.isPotentiallyActive12import io.kotest.engine.tags.parse13import io.kotest.engine.tags.runtimeTags14/**15 * Filters any [Spec] that can be eagerly excluded based on the @[TagExpression] annotation at the class level.16 */17class TagsExcludedSpecInterceptor(18 private val listener: TestEngineListener,19 private val conf: ProjectConfiguration,20) : SpecRefInterceptor {21 private val extensions = SpecExtensions(conf.registry)22 override suspend fun intercept(23 ref: SpecRef,24 fn: suspend (SpecRef) -> Result<Map<TestCase, TestResult>>25 ): Result<Map<TestCase, TestResult>> {26 val potentiallyActive = conf.runtimeTags().parse().isPotentiallyActive(ref.kclass)27 return if (potentiallyActive) {28 fn(ref)29 } else {30 runCatching { listener.specIgnored(ref.kclass, null) }31 .flatMap { extensions.ignored(ref.kclass, "Skipped by tags") }32 .map { emptyMap() }33 }34 }35}...
runtime.kt
Source:runtime.kt
1package io.kotest.engine.tags2import io.kotest.core.Tag3import io.kotest.core.TagExpression4import io.kotest.core.config.ProjectConfiguration5import io.kotest.core.extensions.TagExtension6/**7 * Returns runtime active [Tag]'s by invoking all registered [TagExtension]s and combining8 * any returned tags into a [TagExpression] container.9 */10fun ProjectConfiguration.runtimeTags(): TagExpression {11 val extensions = this.registry.all().filterIsInstance<TagExtension>()12 return if (extensions.isEmpty()) TagExpression.Empty else extensions.map { it.tags() }.reduce { a, b -> a.combine(b) }13}...
ProjectConfiguration.runtimeTags
Using AI Code Generation
1val runtimeTags = ProjectConfiguration.runtimeTags()2val runtimeTags = ProjectConfiguration.runtimeTags()3val runtimeTags = ProjectConfiguration.runtimeTags()4val runtimeTags = ProjectConfiguration.runtimeTags()5val runtimeTags = ProjectConfiguration.runtimeTags()6val runtimeTags = ProjectConfiguration.runtimeTags()7val runtimeTags = ProjectConfiguration.runtimeTags()8val runtimeTags = ProjectConfiguration.runtimeTags()9val runtimeTags = ProjectConfiguration.runtimeTags()10val runtimeTags = ProjectConfiguration.runtimeTags()11val runtimeTags = ProjectConfiguration.runtimeTags()12val runtimeTags = ProjectConfiguration.runtimeTags()13val runtimeTags = ProjectConfiguration.runtimeTags()14val runtimeTags = ProjectConfiguration.runtimeTags()15val runtimeTags = ProjectConfiguration.runtimeTags()
ProjectConfiguration.runtimeTags
Using AI Code Generation
1val tags = ProjectConfiguration.runtimeTags()2val tags = ProjectConfiguration.runtimeTags()3val tags = ProjectConfiguration.runtimeTags()4val tags = ProjectConfiguration.runtimeTags()5val tags = ProjectConfiguration.runtimeTags()6val tags = ProjectConfiguration.runtimeTags()7val tags = ProjectConfiguration.runtimeTags()8val tags = ProjectConfiguration.runtimeTags()9val tags = ProjectConfiguration.runtimeTags()10val tags = ProjectConfiguration.runtimeTags()11val tags = ProjectConfiguration.runtimeTags()12val tags = ProjectConfiguration.runtimeTags()13val tags = ProjectConfiguration.runtimeTags()14val tags = ProjectConfiguration.runtimeTags()15val tags = ProjectConfiguration.runtimeTags()
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!!