How to use withConfiguration method of io.kotest.engine.interceptors.EngineContext class

Best Kotest code snippet using io.kotest.engine.interceptors.EngineContext.withConfiguration

ProjectListenerEngineInterceptorTest.kt

Source:ProjectListenerEngineInterceptorTest.kt Github

copy

Full Screen

...20      }21      val c = ProjectConfiguration()22      c.registry.add(listener)23      ProjectListenerEngineInterceptor.intercept(24         EngineContext.empty.withConfiguration(c)25      ) { EngineResult(emptyList()) }26      fired shouldBe true27   }28   test("should invoke multiple beforeProject listeners") {29      var fired1 = false30      var fired2 = false31      val listener1 = object : BeforeProjectListener {32         override suspend fun beforeProject() {33            fired1 = true34         }35      }36      val listener2 = object : BeforeProjectListener {37         override suspend fun beforeProject() {38            fired2 = true39         }40      }41      val c = ProjectConfiguration()42      c.registry.add(listener1)43      c.registry.add(listener2)44      ProjectListenerEngineInterceptor.intercept(45         EngineContext.empty.withConfiguration(c)46      ) { EngineResult(emptyList()) }47      fired1 shouldBe true48      fired2 shouldBe true49   }50   test("should invoke afterProject listeners") {51      var fired = false52      val listener = object : AfterProjectListener {53         override suspend fun afterProject() {54            fired = true55         }56      }57      val c = ProjectConfiguration()58      c.registry.add(listener)59      ProjectListenerEngineInterceptor.intercept(60         EngineContext.empty.withConfiguration(c)61      ) { EngineResult(emptyList()) }62      fired shouldBe true63   }64   test("should invoke multiple afterProject listeners") {65      var fired1 = false66      var fired2 = false67      val listener1 = object : AfterProjectListener {68         override suspend fun afterProject() {69            fired1 = true70         }71      }72      val listener2 = object : AfterProjectListener {73         override suspend fun afterProject() {74            fired2 = true75         }76      }77      val c = ProjectConfiguration()78      c.registry.add(listener1)79      c.registry.add(listener2)80      ProjectListenerEngineInterceptor.intercept(81         EngineContext.empty.withConfiguration(c)82      ) { EngineResult(emptyList()) }83      fired1 shouldBe true84      fired2 shouldBe true85   }86   test("should return BeforeProjectListener errors wrapped in BeforeProjectListenerException") {87      val listener1 = object : BeforeProjectListener {88         override suspend fun beforeProject() {89            error("whack!")90         }91      }92      val listener2 = object : BeforeProjectListener {93         override suspend fun beforeProject() {94            error("zapp!")95         }96      }97      val c = ProjectConfiguration()98      c.registry.add(listener1)99      c.registry.add(listener2)100      val results = ProjectListenerEngineInterceptor.intercept(101         EngineContext.empty.withConfiguration(c)102      ) { EngineResult(emptyList()) }103      results.errors.filterIsInstance<ExtensionException.BeforeProjectException>().size shouldBe 2104   }105   test("should return AfterProjectListener errors wrapped in AfterProjectListenerException") {106      val listener1 = object : AfterProjectListener {107         override suspend fun afterProject() {108            error("whack!")109         }110      }111      val listener2 = object : AfterProjectListener {112         override suspend fun afterProject() {113            error("zapp!")114         }115      }116      val c = ProjectConfiguration()117      c.registry.add(listener1)118      c.registry.add(listener2)119      val results = ProjectListenerEngineInterceptor.intercept(120         EngineContext.empty.withConfiguration(c)121      ) { EngineResult(emptyList()) }122      results.errors.filterIsInstance<ExtensionException.AfterProjectException>().size shouldBe 2123   }124})...

Full Screen

Full Screen

ProjectExtensionEngineInterceptorTest.kt

Source:ProjectExtensionEngineInterceptorTest.kt Github

copy

Full Screen

...28      }29      val c = ProjectConfiguration()30      c.registry.add(ext1)31      c.registry.add(ext2)32      ProjectExtensionEngineInterceptor.intercept(EngineContext.empty.withConfiguration(c)) { EngineResult.empty }33      fired1 shouldBe true34      fired2 shouldBe true35   }36   test("should invoke downstream after extensions") {37      var fired = false38      val ext1 = object : ProjectExtension {39         override suspend fun interceptProject(context: ProjectContext, callback: suspend (ProjectContext) -> Unit) {40            callback(context)41         }42      }43      val ext2 = object : ProjectExtension {44         override suspend fun interceptProject(context: ProjectContext, callback: suspend (ProjectContext) -> Unit) {45            callback(context)46         }47      }48      val c = ProjectConfiguration()49      c.registry.add(ext1)50      c.registry.add(ext2)51      ProjectExtensionEngineInterceptor.intercept(EngineContext.empty.withConfiguration(c)) {52         fired = true53         EngineResult.empty54      }55      fired shouldBe true56   }57   test("should invoke downstream without extensions") {58      var fired = false59      ProjectExtensionEngineInterceptor.intercept(EngineContext.empty) {60         fired = true61         EngineResult.empty62      }63      fired shouldBe true64   }65   test("should propagate tag changes") {66      var tags = TagExpression("none")67      val ext = object : ProjectExtension {68         override suspend fun interceptProject(context: ProjectContext, callback: suspend (ProjectContext) -> Unit) {69            callback(context.copy(tags = context.tags.include("bar")))70         }71      }72      val c = ProjectConfiguration()73      c.registry.add(ext)74      ProjectExtensionEngineInterceptor.intercept(EngineContext.empty.withTags(TagExpression("foo")).withConfiguration(c)) {75         tags = it.tags76         EngineResult.empty77      }78      tags.expression shouldBe "foo & bar"79   }80})...

Full Screen

Full Screen

EngineInterceptor.kt

Source:EngineInterceptor.kt Github

copy

Full Screen

...44   }45   fun withListener(listener: TestEngineListener): EngineContext {46      return EngineContext(suite, listener, tags, configuration)47   }48   fun withConfiguration(c: ProjectConfiguration): EngineContext {49      return EngineContext(suite, listener, tags, c)50   }51   fun withTags(tags: TagExpression): EngineContext {52      return EngineContext(suite, listener, tags, configuration)53   }54}55fun ProjectContext.toEngineContext(context: EngineContext): EngineContext {56   return EngineContext(57      suite,58      context.listener,59      tags,60      configuration61   )62}...

Full Screen

Full Screen

EmptyTestSuiteInterceptorTest.kt

Source:EmptyTestSuiteInterceptorTest.kt Github

copy

Full Screen

...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") {31         val tc = TestCase(32            EmptyTestSuiteInterceptorTest::class.toDescriptor().append("foo"),33            TestName("foo"),34            EmptyTestSuiteInterceptorTest(),35            {},36            sourceRef(),37            TestType.Test38         )39         val conf = ProjectConfiguration()40         conf.failOnEmptyTestSuite = true41         val result = EmptyTestSuiteInterceptor.intercept(42            EngineContext.empty.withConfiguration(conf)43         ) {44            it.listener.testFinished(tc, TestResult.Success(Duration.ZERO))45            EngineResult.empty46         }47         result.errors.filterIsInstance<EmptyTestSuiteException>().shouldHaveSize(0)48      }49   }50}...

Full Screen

Full Screen

SpecSortEngineInterceptorTest.kt

Source:SpecSortEngineInterceptorTest.kt Github

copy

Full Screen

...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),28               )29            )30         )31      ) {32         sorted = it.suite.specs33         EngineResult(emptyList())34      }35      sorted.map { it.kclass } shouldBe listOf(BangDisableFunSpec::class, FocusTest::class, IgnoredTestsTest::class)36   }...

Full Screen

Full Screen

ProjectTimeoutEngineInterceptorTest.kt

Source:ProjectTimeoutEngineInterceptorTest.kt Github

copy

Full Screen

...12class 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>()22   }23   test("should not return ProjectTimeoutException when project does not time out") {24      val c = ProjectConfiguration()25      c.projectTimeout = 100000.milliseconds26      val result = ProjectTimeoutEngineInterceptor.intercept(EngineContext.empty.withConfiguration(c)) {27         delay(1)28         EngineResult.empty29      }30      result.errors.size shouldBe 031   }32})...

Full Screen

Full Screen

withConfiguration

Using AI Code Generation

copy

Full Screen

1val engineContext = EngineContext( engine = engine, configuration = configuration )2val engineContext = EngineContext( engine = engine, configuration = configuration )3val engineContext = EngineContext( engine = engine, configuration = configuration )4val engineContext = EngineContext( engine = engine, configuration = configuration )5val engineContext = EngineContext( engine = engine, configuration = configuration )6val engineContext = EngineContext( engine = engine, configuration = configuration )7val engineContext = EngineContext( engine = engine, configuration = configuration )8val engineContext = EngineContext( engine = engine, configuration = configuration )9val engineContext = EngineContext( engine = engine, configuration = configuration )10val engineContext = EngineContext( engine = engine, configuration = configuration )11val engineContext = EngineContext( engine = engine, configuration = configuration )12val engineContext = EngineContext( engine = engine, configuration = configuration )13val engineContext = EngineContext( engine = engine, configuration = configuration )14val engineContext = EngineContext( engine = engine, configuration = configuration )15val engineContext = EngineContext( engine = engine, configuration = configuration )

Full Screen

Full Screen

withConfiguration

Using AI Code Generation

copy

Full Screen

1val config = ProjectConfig()2withConfig(config) {3}4class ProjectConfig : AbstractProjectConfig() {5override fun listeners() = listOf(MyListener())6}7class MyListener : TestListener {8override suspend fun beforeSpec(spec: Spec) {9println("beforeSpec")10}11override suspend fun afterSpec(spec: Spec) {12println("afterSpec")13}14}15class ProjectConfig : AbstractProjectConfig() {16override fun listeners() = listOf(MyListener())17}18class MyListener : TestListener {19override suspend fun beforeSpec(spec: Spec) {20println("beforeSpec")21}22override suspend fun afterSpec(spec: Spec) {23println("afterSpec")24}25}26class ProjectConfigTest : FunSpec({27withConfig(ProjectConfig()) {28}29})30class ProjectConfigTest : DescribeSpec({31withConfig(ProjectConfig()) {32}33})34class ProjectConfigTest : ExpectSpec({35withConfig(ProjectConfig()) {36}37})38class ProjectConfigTest : FeatureSpec({39withConfig(ProjectConfig()) {40}41})

Full Screen

Full Screen

withConfiguration

Using AI Code Generation

copy

Full Screen

1class   EngineContextConfigTest  :  FunSpec ({2  test ( "test" ) {3    withConfiguration (4          configuration  =  KotestEngineConfiguration (5              specExecutionTimeout  =  Duration . ofSeconds ( 1 ),6              determineSpecClasses  =  {  emptyList ()  },7              filter  =  {  true  },8              extensions  =  emptyList (),9              listeners  =  emptyList (),10          block  =  {11              val  conf  =  configuration ()12              conf . specExecutionTimeout  shouldBe   Duration . ofSeconds ( 1 )13              conf . determineSpecClasses  shouldBe   {  emptyList ()  }14              conf . filter  shouldBe   {  true  }15              conf . extensions  shouldBe   emptyList < Extension >()16              conf . listeners  shouldBe   emptyList < TestEngineListener >()17          }18  }19})

Full Screen

Full Screen

withConfiguration

Using AI Code Generation

copy

Full Screen

1val config = EngineConfiguration (2withConfiguration(config) {3}4class MySpec : FunSpec({5}) {6override fun configuration() = super.configuration().copy(7}8class MySpec : FunSpec({9}) {10override fun configuration() = super.configuration().copy(11}12class MySpec : FreeSpec({13}) {14override fun configuration() = super.configuration().copy(15}16class MySpec : DescribeSpec({17}) {18override fun configuration() = super.configuration().copy(19}20class MySpec : StringSpec({21}) {22override fun configuration() = super.configuration().copy(23}24class MySpec : WordSpec({25}) {26override fun configuration() = super.configuration().copy(27}28class MySpec : BehaviorSpec({29}) {30override fun configuration() = super.configuration().copy(

Full Screen

Full Screen

withConfiguration

Using AI Code Generation

copy

Full Screen

1fun main() {2   EngineLauncher()3      .withConfiguration {4         testTimeout = Duration.ofSeconds(5)5      }6      .withSpec(MySpec::class)7      .launch()8}9fun main() {10   EngineLauncher()11      .withConfiguration {12         testTimeout = Duration.ofSeconds(5)13      }14      .withSpec(MySpec::class)15      .launch()16}17fun main() {18   EngineLauncher()19      .withConfiguration {20         testTimeout = Duration.ofSeconds(5)21      }22      .withSpec(MySpec::class)23      .launch()24}25override fun configuration() = super.configuration().copy(26}27class MySpec : StringSpec({28}) {29override fun configuration() = super.configuration().copy(30}31class MySpec : WordSpec({32}) {33override fun configuration() = super.configuration().copy(34}35class MySpec : BehaviorSpec({36}) {37override fun configuration() = super.configuration().copy(

Full Screen

Full Screen

withConfiguration

Using AI Code Generation

copy

Full Screen

1fun main() {2   EngineLauncher()3      .withConfiguration {4         testTimeout = Duration.ofSeconds(5)5      }6      .withSpec(MySpec::class)7      .launch()8}9fun main() {10   EngineLauncher()11      .withConfiguration {12         testTimeout = Duration.ofSeconds(5)13      }14      .withSpec(MySpec::class)15      .launch()16}17fun main() {18   EngineLauncher()19      .withConfiguration {20         testTimeout = Duration.ofSeconds(5)21      }22      .withSpec(MySpec::class)23      .launch()24}

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