Best Kotest code snippet using io.kotest.core.spec.DslDrivenSpec.seal
SpecExecutor.kt
Source:SpecExecutor.kt
...106 /**107 * Creates an instance of the given [SpecRef], notifies users of the instantiation event108 * or instantiation failure, and returns a Result with the error or spec.109 *110 * After this method is called the spec is sealed.111 */112 private suspend fun createInstance(ref: SpecRef): Result<Spec> =113 ref.instance(context.configuration.registry)114 .onFailure { extensions.specInstantiationError(ref.kclass, it) }115 .flatMap { spec -> extensions.specInstantiated(spec).map { spec } }116 .onSuccess { if (it is DslDrivenSpec) it.seal() }117}118interface SpecExecutorDelegate {119 suspend fun execute(spec: Spec): Map<TestCase, TestResult>120}121@ExperimentalKotest122internal expect fun createSpecExecutorDelegate(123 listener: TestEngineListener,124 defaultCoroutineDispatcherFactory: CoroutineDispatcherFactory,125 configuration: ProjectConfiguration,126): SpecExecutorDelegate...
DslDrivenSpec.kt
Source:DslDrivenSpec.kt
...16 /**17 * Contains the [RootTest]s that have been registered on this spec.18 */19 private var rootTests = emptyList<RootTest>()20 private var sealed = false21 private val globalExtensions = mutableListOf<Extension>()22 /**23 * Marks that this spec has been instantiated and all root tests have been registered.24 * After this point, no further root tests are allowed to be defined.25 */26 fun seal() {27 sealed = true28 }29 override fun rootTests(): List<RootTest> {30 return rootTests31 }32 override fun globalExtensions(): List<Extension> {33 return globalExtensions.toList()34 }35 override fun add(test: RootTest) {36 if (sealed) throw InvalidDslException("Cannot add a root test after the spec has been instantiated: ${test.name.testName}")37 rootTests = rootTests + test38 }39 /**40 * Include the tests and extensions from the given [TestFactory] in this spec.41 * Tests are added in order from where this include was invoked using configuration and42 * settings at the time the method was invoked.43 */44 fun include(factory: TestFactory) {45 factory.tests.forEach { add(it.copy(factoryId = factory.factoryId)) }46 register(factory.extensions)47 }48 /**49 * Includes the tests from the given [TestFactory] in this spec or factory, with the given50 * prefixed added to each of the test's name....
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!!