Best Kotest code snippet using io.kotest.core.extensions.SpecExecutionOrderExtension.sort
SpecSortEngineInterceptor.kt
Source:SpecSortEngineInterceptor.kt
...5import io.kotest.engine.EngineResult6import io.kotest.engine.spec.DefaultSpecExecutionOrderExtension7import io.kotest.mpp.log8/**9 * An [EngineInterceptor] that sorts the [TestSuite] according to registered [SpecExecutionOrderExtension]s10 * or falling back to the [DefaultSpecExecutionOrderExtension].11 */12@KotestInternal13internal object SpecSortEngineInterceptor : EngineInterceptor {14 override suspend fun intercept(15 context: EngineContext,16 execute: suspend (EngineContext) -> EngineResult17 ): EngineResult {18 // spec classes are ordered using SpecExecutionOrderExtension extensions19 val exts = context.configuration.registry.all().filterIsInstance<SpecExecutionOrderExtension>().ifEmpty {20 listOf(DefaultSpecExecutionOrderExtension(context.configuration.specExecutionOrder, context.configuration))21 }22 log { "SpecSortEngineInterceptor: Sorting specs using extensions $exts" }23 val specs = exts.fold(context.suite.specs) { acc, op -> op.sort(acc) }24 return execute(context.withTestSuite(TestSuite(specs)))25 }26}...
ordering.kt
Source:ordering.kt
...5import io.kotest.core.spec.SpecRef6import kotlin.random.Random7/**8 * A [SpecExecutionOrderExtension] which uses the value of the given [SpecExecutionOrder] parameter9 * to delegate to a [SpecSorter] perform sorting.10 */11internal class DefaultSpecExecutionOrderExtension(12 private val order: SpecExecutionOrder,13 private val configuration: ProjectConfiguration,14) : SpecExecutionOrderExtension {15 override fun sort(specs: List<SpecRef>): List<SpecRef> {16 return when (order) {17 SpecExecutionOrder.Undefined -> specs18 SpecExecutionOrder.Lexicographic -> LexicographicSpecSorter.sort(specs)19 SpecExecutionOrder.Annotated -> AnnotatedSpecSorter.sort(specs)20 SpecExecutionOrder.FailureFirst -> FailureFirstSorter().sort(specs)21 SpecExecutionOrder.Random -> {22 val random = when (val seed = configuration.randomOrderSeed) {23 null -> Random.Default24 else -> Random(seed)25 }26 RandomSpecSorter(random).sort(specs)27 }28 }29 }30}...
SpecExecutionOrderExtension.kt
Source:SpecExecutionOrderExtension.kt
1package io.kotest.core.extensions2import io.kotest.core.spec.SpecRef3/**4 * An extension point that is used to sort specs before execution.5 *6 * If multiple instances of this extension are defined then all will be7 * invoked but the order of invocation is undefined.8 *9 * If no [SpecExecutionOrderExtension]s are registered, then specs will be10 * sorted using the value of [specExecutionOrder] defined in configuration.11 */12interface SpecExecutionOrderExtension {13 fun sort(specs: List<SpecRef>): List<SpecRef>14}...
sort
Using AI Code Generation
1val order = SpecExecutionOrderExtension()2val list = listOf("a", "b", "c")3val sorted = order.sort(list)4println(sorted)5val order = SpecExecutionOrderExtension()6val list = listOf("c", "b", "a")7val sorted = order.sort(list)8println(sorted)9val order = SpecExecutionOrderExtension()10val list = listOf("a", "c", "b")11val sorted = order.sort(list)12println(sorted)13val order = SpecExecutionOrderExtension()14val list = listOf("c", "b", "a")15val sorted = order.sort(list)16println(sorted)17val order = SpecExecutionOrderExtension()18val list = listOf("b", "a", "c")19val sorted = order.sort(list)20println(sorted)21val order = SpecExecutionOrderExtension()22val list = listOf("b", "c", "a")23val sorted = order.sort(list)24println(sorted)25val order = SpecExecutionOrderExtension()26val list = listOf("a", "b", "c")27val sorted = order.sort(list)28println(sorted)29val order = SpecExecutionOrderExtension()30val list = listOf("b", "a", "c")31val sorted = order.sort(list)32println(sorted)
sort
Using AI Code Generation
1SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedByDescending { it.name } })2SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedBy { it.name } })3SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.shuffled() })4SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedBy { it.name } })5SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedByDescending { it.name } })6SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.shuffled() })7SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedBy { it.name } })8SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedByDescending { it.name } })9SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.shuffled() })10SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedBy { it.name } })11SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedByDescending { it.name } })12SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.shuffled() })13SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedBy { it.name } })14SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension.SpecExecutionOrdering { specs -> specs.sortedByDescending { it.name } })15SpecExecutionOrderExtension.registerSpecExecutionOrdering(SpecExecutionOrderExtension
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!!