How to use TestEngineInterceptors class of io.kotest.engine package

Best Kotest code snippet using io.kotest.engine.TestEngineInterceptors

TestEngineLauncher.kt

Source:TestEngineLauncher.kt Github

copy

Full Screen

1@file:Suppress("unused", "MemberVisibilityCanBePrivate")2package io.kotest.engine3import io.kotest.common.runBlocking4import io.kotest.common.runPromise5import io.kotest.core.TagExpression6import io.kotest.core.config.AbstractProjectConfig7import io.kotest.core.config.ProjectConfiguration8import io.kotest.core.extensions.Extension9import io.kotest.core.project.TestSuite10import io.kotest.core.spec.Spec11import io.kotest.core.spec.SpecRef12import io.kotest.engine.config.ConfigManager13import io.kotest.engine.config.detectAbstractProjectConfigs14import io.kotest.engine.config.loadProjectConfigFromClassname15import io.kotest.engine.extensions.SpecifiedTagsTagExtension16import io.kotest.engine.listener.NoopTestEngineListener17import io.kotest.engine.listener.PinnedSpecTestEngineListener18import io.kotest.engine.listener.TeamCityTestEngineListener19import io.kotest.engine.listener.TestEngineListener20import io.kotest.engine.listener.ThreadSafeTestEngineListener21import io.kotest.mpp.log22import kotlin.reflect.KClass23/**24 * A builder class for creating and executing tests via the [TestEngine].25 *26 * Entry point for tests generated through the compiler plugins, and so the27 * public api cannot have breaking changes.28 */29class TestEngineLauncher(30 private val listener: TestEngineListener,31 private val projectConfiguration: ProjectConfiguration,32 private val configs: List<AbstractProjectConfig>,33 private val refs: List<SpecRef>,34 private val tagExpression: TagExpression?,35) {36 constructor() : this(37 NoopTestEngineListener,38 ProjectConfiguration(),39 emptyList(),40 emptyList(),41 null,42 )43 constructor(listener: TestEngineListener) : this(44 listener,45 ProjectConfiguration(),46 emptyList(),47 emptyList(),48 null,49 )50 /**51 * Convenience function to be called by the native code gen to set up the TeamCity listener.52 */53 fun withTeamCityListener(): TestEngineLauncher {54 return withListener(TeamCityTestEngineListener())55 }56 /**57 * Replace the listener with the given value.58 */59 fun withListener(listener: TestEngineListener): TestEngineLauncher {60 return TestEngineLauncher(61 listener = listener,62 projectConfiguration = projectConfiguration,63 configs = configs,64 refs = refs,65 tagExpression = tagExpression,66 )67 }68 fun withSpecs(vararg specs: Spec): TestEngineLauncher {69 return TestEngineLauncher(70 listener = listener,71 projectConfiguration = projectConfiguration,72 configs = configs,73 refs = specs.toList().map { SpecRef.Singleton(it) },74 tagExpression = tagExpression,75 )76 }77 fun withClasses(vararg specs: KClass<out Spec>): TestEngineLauncher = withClasses(specs.toList())78 fun withClasses(specs: List<KClass<out Spec>>): TestEngineLauncher {79 return TestEngineLauncher(80 listener = listener,81 projectConfiguration = projectConfiguration,82 configs = configs,83 refs = specs.toList().map { SpecRef.Reference(it) },84 tagExpression = tagExpression,85 )86 }87 /**88 * Adds a [AbstractProjectConfig] that was detected by the compiler plugin.89 */90 @Deprecated("Use withProjectConfig. Will be removed once compiler plugins are updated")91 fun withConfig(vararg projectConfig: AbstractProjectConfig): TestEngineLauncher {92 return withProjectConfig(*projectConfig)93 }94 /**95 * Adds a [AbstractProjectConfig] that was detected by the compiler plugin.96 */97 fun withProjectConfig(vararg projectConfig: AbstractProjectConfig): TestEngineLauncher {98 return TestEngineLauncher(99 listener = listener,100 projectConfiguration = projectConfiguration,101 configs = configs + projectConfig,102 refs = refs,103 tagExpression = tagExpression,104 )105 }106 fun withTagExpression(expression: TagExpression?): TestEngineLauncher {107 return TestEngineLauncher(108 listener = listener,109 projectConfiguration = projectConfiguration,110 configs = configs,111 refs = refs,112 tagExpression = expression,113 )114 }115 /**116 * Returns a copy of this launcher with the given [extensions] added to the configuration.117 *118 * Note: If after invoking this method, the [withConfiguration] is invoked, then any changes119 * here will be lost.120 */121 fun withExtensions(vararg extensions: Extension): TestEngineLauncher = withExtensions(extensions.toList())122 /**123 * Returns a copy of this launcher with the given [extensions] added to the configuration.124 *125 * Note: If after invoking this method, the [withConfiguration] is invoked, then any changes126 * here will be lost.127 */128 fun withExtensions(extensions: List<Extension>): TestEngineLauncher {129 extensions.forEach { projectConfiguration.registry.add(it) }130 return this131 }132 fun withConfiguration(configuration: ProjectConfiguration): TestEngineLauncher {133 return TestEngineLauncher(134 listener = listener,135 projectConfiguration = configuration,136 configs = configs,137 refs = refs,138 tagExpression = tagExpression,139 )140 }141 fun toConfig(): TestEngineConfig {142 // if the engine was configured with explicit tags, we register those via a tag extension143 tagExpression?.let { projectConfiguration.registry.add(SpecifiedTagsTagExtension(it)) }144 return TestEngineConfig(145 listener = ThreadSafeTestEngineListener(146 PinnedSpecTestEngineListener(147 listener148 )149 ),150 interceptors = testEngineInterceptors(),151 configuration = ConfigManager.initialize(152 projectConfiguration,153 configs + detectAbstractProjectConfigs() + listOfNotNull(loadProjectConfigFromClassname())154 ),155 tagExpression,156 )157 }158 fun testSuite(): TestSuite = TestSuite(refs)159 /**160 * Launch the [TestEngine] in an existing coroutine without blocking.161 */162 suspend fun async(): EngineResult {163 log { "TestEngineLauncher: Launching Test Engine" }164 val engine = TestEngine(toConfig())165 return engine.execute(testSuite())166 }167 /**168 * Launch the [TestEngine] created from this builder and block the thread until execution has completed.169 * This method will throw on JS.170 */171 fun launch(): EngineResult {172 log { "TestEngineLauncher: Launching Test Engine" }173 return runBlocking {174 val engine = TestEngine(toConfig())175 engine.execute(testSuite())176 }177 }178 /**179 * Launch the [TestEngine] created from this builder using a Javascript promise.180 * This method will throw on JVM or native.181 */182 fun promise() {183 log { "TestEngineLauncher: Launching Test Engine in Javascript promise" }184 runPromise {185 val engine = TestEngine(toConfig())186 engine.execute(testSuite())187 }188 }189}...

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

interceptors.kt

Source:interceptors.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

TestEngineInterceptors

Using AI Code Generation

copy

Full Screen

1val engine = TestEngineInterceptors()2engine.interceptTestEngine { engine, execute ->3}4engine.interceptTestEngine { engine, execute ->5}6engine.interceptSpec { spec, execute ->7}8engine.interceptSpec { spec, execute ->9}10engine.interceptTestCase { test, execute ->11}12engine.interceptTestCase { test, execute ->13}14engine.interceptTest { test, execute ->15}16engine.interceptTest { test, execute ->17}18engine.interceptTestFinalize { test, result ->19}20engine.interceptTestFinalize { test, result ->21}22engine.interceptSpecFinalize { spec, result ->23}24engine.interceptSpecFinalize { spec, result ->25}26engine.interceptTestEngineFinalize { engine, result ->27}28engine.interceptTestEngineFinalize { engine, result ->29}30val engine = TestEngineInterceptors()31engine.interceptTestEngine { engine, execute ->32}33engine.interceptTestEngine { engine, execute ->34}35engine.interceptSpec { spec, execute ->36}37engine.interceptSpec { spec, execute ->38}39engine.interceptTestCase { test, execute ->40}41engine.interceptTestCase { test, execute ->42}43engine.interceptTest { test, execute ->44}45engine.interceptTest { test, execute ->46}

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.

Most used methods in TestEngineInterceptors

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful