How to use interceptors class of io.kotest.engine.test.interceptors package

Best Kotest code snippet using io.kotest.engine.test.interceptors.interceptors

TestEngine.kt

Source:TestEngine.kt Github

copy

Full Screen

...5import 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}...

Full Screen

Full Screen

EmptyTestSuiteInterceptorTest.kt

Source:EmptyTestSuiteInterceptorTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.engine.interceptors2import io.kotest.common.ExperimentalKotest3import io.kotest.common.KotestInternal4import io.kotest.core.config.ProjectConfiguration5import io.kotest.core.descriptors.append6import io.kotest.core.descriptors.toDescriptor7import io.kotest.core.names.TestName8import io.kotest.core.source.sourceRef9import io.kotest.core.spec.style.FunSpec10import io.kotest.core.test.TestCase11import io.kotest.core.test.TestResult12import io.kotest.core.test.TestType13import io.kotest.engine.EngineResult14import io.kotest.engine.interceptors.EmptyTestSuiteException15import io.kotest.engine.interceptors.EmptyTestSuiteInterceptor16import io.kotest.engine.interceptors.EngineContext17import io.kotest.matchers.collections.shouldHaveSize18import kotlin.time.Duration19@ExperimentalKotest20@KotestInternal21class EmptyTestSuiteInterceptorTest : FunSpec() {22 init {23 test("should error on empty test suite") {24 val conf = ProjectConfiguration()25 conf.failOnEmptyTestSuite = true26 val result =27 EmptyTestSuiteInterceptor.intercept(EngineContext.empty.withConfiguration(conf)) { EngineResult.empty }28 result.errors.filterIsInstance<EmptyTestSuiteException>().shouldHaveSize(1)29 }30 test("should not error on non empty test suite") {...

Full Screen

Full Screen

TestEngineStartedFinishedInterceptorTest.kt

Source:TestEngineStartedFinishedInterceptorTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.engine.interceptors2import io.kotest.common.KotestInternal3import io.kotest.core.spec.style.FunSpec4import io.kotest.engine.EngineResult5import io.kotest.engine.interceptors.EngineContext6import io.kotest.engine.interceptors.TestEngineStartedFinishedInterceptor7import io.kotest.engine.listener.AbstractTestEngineListener8import io.kotest.matchers.collections.shouldHaveSize9import io.kotest.matchers.shouldBe10@KotestInternal11class TestEngineStartedFinishedInterceptorTest : FunSpec({12 test("should invoke engineStarted before downstream") {13 var fired = ""14 val listener = object : AbstractTestEngineListener() {15 override suspend fun engineStarted() {16 fired += "a"17 }18 }19 TestEngineStartedFinishedInterceptor.intercept(20 EngineContext.empty.mergeListener(listener)...

Full Screen

Full Screen

SpecSortEngineInterceptorTest.kt

Source:SpecSortEngineInterceptorTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.engine.interceptors2import com.sksamuel.kotest.engine.active.BangDisableFunSpec3import com.sksamuel.kotest.engine.active.FocusTest4import com.sksamuel.kotest.engine.active.IgnoredTestsTest5import io.kotest.core.annotation.Isolate6import io.kotest.core.config.ProjectConfiguration7import io.kotest.core.project.TestSuite8import io.kotest.core.spec.SpecExecutionOrder9import io.kotest.core.spec.SpecRef10import io.kotest.core.spec.style.FunSpec11import io.kotest.engine.EngineResult12import io.kotest.engine.interceptors.EngineContext13import io.kotest.engine.interceptors.SpecSortEngineInterceptor14import io.kotest.matchers.shouldBe15@Isolate16class SpecSortEngineInterceptorTest : FunSpec({17 test("should sort classes") {18 val c = ProjectConfiguration()19 c.specExecutionOrder = SpecExecutionOrder.Lexicographic20 var sorted = emptyList<SpecRef>()21 SpecSortEngineInterceptor.intercept(22 EngineContext.empty.withConfiguration(c).withTestSuite(23 TestSuite(24 listOf(25 SpecRef.Reference(IgnoredTestsTest::class),26 SpecRef.Reference(BangDisableFunSpec::class),27 SpecRef.Reference(FocusTest::class),...

Full Screen

Full Screen

ProjectTimeoutEngineInterceptorTest.kt

Source:ProjectTimeoutEngineInterceptorTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.engine.interceptors2import io.kotest.core.config.ProjectConfiguration3import io.kotest.core.spec.style.FunSpec4import io.kotest.engine.EngineResult5import io.kotest.engine.interceptors.EngineContext6import io.kotest.engine.interceptors.ProjectTimeoutEngineInterceptor7import io.kotest.engine.interceptors.ProjectTimeoutException8import io.kotest.matchers.shouldBe9import io.kotest.matchers.types.shouldBeInstanceOf10import kotlinx.coroutines.delay11import kotlin.time.Duration.Companion.milliseconds12class ProjectTimeoutEngineInterceptorTest : FunSpec({13 test("should return ProjectTimeoutException when project times out") {14 val c = ProjectConfiguration()15 c.projectTimeout = 1.milliseconds16 val result = ProjectTimeoutEngineInterceptor.intercept(EngineContext.empty.withConfiguration(c)) {17 delay(1000)18 EngineResult.empty19 }20 result.errors.size shouldBe 121 result.errors.first().shouldBeInstanceOf<ProjectTimeoutException>()...

Full Screen

Full Screen

interceptors.kt

Source:interceptors.kt Github

copy

Full Screen

1package io.kotest.engine2import io.kotest.common.KotestInternal3import io.kotest.engine.interceptors.DumpConfigInterceptor4import io.kotest.engine.interceptors.EmptyTestSuiteInterceptor5import io.kotest.engine.interceptors.EngineInterceptor6import io.kotest.engine.interceptors.KotestPropertiesInterceptor7import io.kotest.engine.interceptors.ProjectExtensionEngineInterceptor8import io.kotest.engine.interceptors.ProjectListenerEngineInterceptor9import io.kotest.engine.interceptors.ProjectTimeoutEngineInterceptor10import io.kotest.engine.interceptors.SpecSortEngineInterceptor11import io.kotest.engine.interceptors.TestDslStateInterceptor12import io.kotest.engine.interceptors.TestEngineInitializedInterceptor13import io.kotest.engine.interceptors.TestEngineStartedFinishedInterceptor14import io.kotest.engine.interceptors.WriteFailuresInterceptor15@KotestInternal16actual fun testEngineInterceptors(): List<EngineInterceptor> {17 return listOfNotNull(18 TestEngineStartedFinishedInterceptor,19 KotestPropertiesInterceptor,20 TestDslStateInterceptor,21 SpecSortEngineInterceptor,22 ProjectExtensionEngineInterceptor,23 ProjectListenerEngineInterceptor,24 ProjectTimeoutEngineInterceptor,25 EmptyTestSuiteInterceptor,26 WriteFailuresInterceptor,27 DumpConfigInterceptor,28 TestEngineInitializedInterceptor,...

Full Screen

Full Screen

TestEngineInterceptors.kt

Source:TestEngineInterceptors.kt Github

copy

Full Screen

1package io.kotest.engine2import io.kotest.common.KotestInternal3import io.kotest.engine.interceptors.EmptyTestSuiteInterceptor4import io.kotest.engine.interceptors.EngineInterceptor5import io.kotest.engine.interceptors.ProjectExtensionEngineInterceptor6import io.kotest.engine.interceptors.ProjectListenerEngineInterceptor7import io.kotest.engine.interceptors.ProjectTimeoutEngineInterceptor8import io.kotest.engine.interceptors.SpecSortEngineInterceptor9import io.kotest.engine.interceptors.TestDslStateInterceptor10import io.kotest.engine.interceptors.TestEngineInitializedInterceptor11import io.kotest.engine.interceptors.TestEngineStartedFinishedInterceptor12@KotestInternal13internal actual fun testEngineInterceptors(): List<EngineInterceptor> {14 return listOfNotNull(15 TestEngineStartedFinishedInterceptor,16 ProjectTimeoutEngineInterceptor,17 TestDslStateInterceptor,18 SpecSortEngineInterceptor,19 ProjectExtensionEngineInterceptor,20 ProjectListenerEngineInterceptor,21 EmptyTestSuiteInterceptor,22 TestEngineInitializedInterceptor,23 )24}...

Full Screen

Full Screen

TestEngineInitializeInterceptorTest.kt

Source:TestEngineInitializeInterceptorTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.engine.interceptors2import io.kotest.core.spec.style.FunSpec3import io.kotest.engine.EngineResult4import io.kotest.engine.interceptors.EngineContext5import io.kotest.engine.interceptors.TestEngineInitializedInterceptor6import io.kotest.engine.listener.AbstractTestEngineListener7import io.kotest.matchers.booleans.shouldBeTrue8class TestEngineInitializeInterceptorTest : FunSpec({9 test("should invoke initialize") {10 var fired = false11 val listener = object : AbstractTestEngineListener() {12 override suspend fun engineInitialized(context: EngineContext) {13 fired = true14 }15 }16 TestEngineInitializedInterceptor.intercept(17 EngineContext.empty.mergeListener(listener)18 ) { EngineResult.empty }19 fired.shouldBeTrue()...

Full Screen

Full Screen

interceptors

Using AI Code Generation

copy

Full Screen

1class MyEngineInterceptor : EngineInterceptor {2 override suspend fun intercept(3 execute: suspend (EngineContext) -> EngineResult4 ): EngineResult {5 val result = execute(context)6 }7}8class MyTestInterceptor : TestInterceptor {9 override suspend fun intercept(10 execute: suspend (TestContext) -> TestResult11 ): TestResult {12 val result = execute(context)13 }14}15class MySpecInterceptor : SpecInterceptor {16 override suspend fun intercept(17 execute: suspend (SpecContext) -> SpecResult18 ): SpecResult {19 val result = execute(context)20 }21}22class MyProjectInterceptor : ProjectInterceptor {23 override suspend fun intercept(24 execute: suspend (ProjectContext) -> ProjectResult25 ): ProjectResult {26 val result = execute(context)27 }28}29class MyTestEngineListener : TestEngineListener {30 override suspend fun engineStarted(t: List<Spec>) {31 }32 override suspend fun engineFinished(t: List<Spec>, results: Map<Spec, Result>) {33 }34}35class MySpecEngineListener : SpecEngineListener {36 override suspend fun specStarted(kclass: KClass<out Spec>) {37 }38 override suspend fun specFinished(kclass: KClass<out Spec>, result: Result) {39 }40}41class MyTestEngineListener : TestEngineListener {42 override suspend fun engineStarted(t: List<Spec>) {43 }44 override suspend fun engineFinished(t: List<Spec>, results: Map<Spec, Result>) {45 }46}47class MySpecEngineListener : SpecEngineListener {48 override suspend fun specStarted(kclass: KClass<out Spec>) {49 }50 override suspend fun specFinished(kclass: KClass<out Spec>, result: Result) {51 }52}53class MySpecStartedListener : SpecStartedListener {

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