Best Kotest code snippet using io.kotest.engine.config.detectAbstractProjectConfigs
TestEngineLauncher.kt
Source:TestEngineLauncher.kt
...9import 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 /**...
ConfigManager.kt
Source:ConfigManager.kt
...49 * Scan the classpath for [AbstractProjectConfig] instances.50 *51 * Note: This will only have an effect on JVM targets.52 */53internal expect fun detectAbstractProjectConfigs(): List<AbstractProjectConfig>...
detectAbstractProjectConfigs.kt
Source:detectAbstractProjectConfigs.kt
1package io.kotest.engine.config2import io.kotest.core.config.AbstractProjectConfig3import io.kotest.core.internal.KotestEngineProperties4import io.kotest.mpp.instantiateOrObject5internal actual fun detectAbstractProjectConfigs(): List<AbstractProjectConfig> {6 // this property is used to disable class path scanning for configurations7 if (System.getProperty(KotestEngineProperties.disableConfigurationClassPathScanning) == "true")8 return emptyList()9 return classgraph().scan().use { result ->10 result.getSubclasses(AbstractProjectConfig::class.java.name)11 .map { Class.forName(it.name) as Class<out AbstractProjectConfig> }12 .mapNotNull { instantiateOrObject(it).getOrNull() }13 }14}
applyConfigs.kt
Source:applyConfigs.kt
...3import io.kotest.core.config.ProjectConfiguration4internal actual fun applyConfigFromSystemProperties(configuration: ProjectConfiguration) {}5internal actual fun applyConfigFromAutoScan(configuration: ProjectConfiguration) {}6internal actual fun applyPlatformDefaults(configuration: ProjectConfiguration) {}7internal actual fun detectAbstractProjectConfigs(): List<AbstractProjectConfig> = emptyList()8internal actual fun loadProjectConfigFromClassname(): AbstractProjectConfig? = null...
detectAbstractProjectConfigs
Using AI Code Generation
1import io.kotest.core.config.AbstractProjectConfig2import io.kotest.core.config.detectAbstractProjectConfigs3import io.kotest.core.spec.style.FunSpec4class Test : FunSpec({5 test("detectAbstractProjectConfigs") {6 val configs = detectAbstractProjectConfigs()7 assert(configs.size == 1)8 assert(configs[0] is ProjectConfig)9 }10})11import io.kotest.core.config.AbstractProjectConfig12import io.kotest.core.config.Project13import io.kotest.core.spec.style.FunSpec14class ProjectConfig : AbstractProjectConfig() {15 override fun beforeAll() {16 }17}18import io.kotest.core.config.AbstractProjectConfig19import io.kotest.core.config.Project20import io.kotest.core.spec.style.FunSpec21class ProjectConfig : AbstractProjectConfig() {22 override fun beforeAll() {23 }24}25import io.kotest.core.config.AbstractProjectConfig26import io.kotest.core.config.Project27import io.kotest.core.spec.style.FunSpec28class ProjectConfig : AbstractProjectConfig() {29 override fun beforeAll() {30 }31}32import io.kotest.core.config.AbstractProjectConfig33import io.kotest.core.config.Project34import io.kotest.core.spec.style.FunSpec35class ProjectConfig : AbstractProjectConfig() {36 override fun beforeAll() {37 }38}39import io.kotest.core.config.AbstractProjectConfig40import io.kotest.core.config.Project41import io.kotest.core.spec.style.FunSpec42class ProjectConfig : AbstractProjectConfig() {43 override fun beforeAll() {44 }45}46import io.kotest.core.config.AbstractProjectConfig47import io.kotest.core.config.Project48import io.kotest.core.spec.style.FunSpec49class ProjectConfig : AbstractProjectConfig() {50 override fun beforeAll() {51 }52}53import io.kotest.core.config.AbstractProjectConfig54import io.kotest.core.config.Project55import io.kotest.core.spec.style.Fun
detectAbstractProjectConfigs
Using AI Code Generation
1val abstractProjectConfigs = detectAbstractProjectConfigs ( )2val abstractTestConfigs = detectAbstractTestConfigs ( )3val abstractProjectConfigs = detectAbstractProjectConfigs ( )4val abstractTestConfigs = detectAbstractTestConfigs ( )5val abstractProjectConfigs = detectAbstractProjectConfigs ( )6val abstractTestConfigs = detectAbstractTestConfigs ( )7val abstractProjectConfigs = detectAbstractProjectConfigs ( )8val abstractTestConfigs = detectAbstractTestConfigs ( )9val abstractProjectConfigs = detectAbstractProjectConfigs ( )10val abstractTestConfigs = detectAbstractTestConfigs ( )11val abstractProjectConfigs = detectAbstractProjectConfigs ( )12val abstractTestConfigs = detectAbstractTestConfigs ( )
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!!