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

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

TestEngineLauncher.kt

Source:TestEngineLauncher.kt Github

copy

Full Screen

...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

SystemPropertyFiltersTests.kt

Source:SystemPropertyFiltersTests.kt Github

copy

Full Screen

...7import io.kotest.core.annotation.Isolate8import io.kotest.core.spec.Spec9import io.kotest.core.spec.style.FunSpec10import io.kotest.core.test.TestScope11import io.kotest.engine.TestEngineLauncher12import io.kotest.extensions.system.withSystemProperties13import io.kotest.matchers.collections.shouldContainExactly14import io.kotest.matchers.shouldBe15import kotlin.reflect.KClass16private val executed = mutableListOf<String>()17internal fun TestScope.testAndIncrementCounter() {18   1 shouldBe 1 // fake assertion so tests don't fail from fail on no assertion setting if it's set19   executed.add(this.testCase.name.testName)20}21private fun numberOfTestsRunShouldBe(expected: Int) {22   executed.size shouldBe expected23}24private fun testsRunShouldBe(vararg name: String) {25   executed shouldContainExactly name.toList()26}27private val testSuite = listOf<KClass<out Spec>>(28   DistantFutureSciFiTests::class,29   NearFutureSciFiTests::class,30   BarTests::class,31   FooTests::class,32)33/**34 * Test that the filter expressions in [KotestEngineProperties.filterTests] and35 * [KotestEngineProperties.filterSpecs] work similarly to how gradle filters in --tests described in36 * https://docs.gradle.org/current/userguide/java_testing.html#full_qualified_name_pattern37 */38@KotestInternal39@Isolate40class SystemPropertyTestFiltersTests : FunSpec({41   beforeTest {42      executed.clear()43   }44   test("include all classes when filter specs is blank") {45      withSystemProperties(46         mapOf(47            KotestEngineProperties.filterSpecs to "",48            KotestEngineProperties.filterTests to ""49         )50      ) { TestEngineLauncher().withClasses(testSuite).withConfiguration(ProjectConfiguration()).launch() }51      numberOfTestsRunShouldBe(13)52   }53   test("filters a specific class") {54      withSystemProperties(55         mapOf(56            KotestEngineProperties.filterSpecs to "*DistantFutureSciFiTests",57            KotestEngineProperties.filterTests to ""58         )59      ) { TestEngineLauncher().withClasses(testSuite).withConfiguration(ProjectConfiguration()).launch() }60      numberOfTestsRunShouldBe(7)61   }62   test("filters a class prefix") {63      withSystemProperties(64         mapOf(65            KotestEngineProperties.filterSpecs to "*FutureSciFiTests",66            KotestEngineProperties.filterTests to ""67         )68      ) { TestEngineLauncher().withClasses(testSuite).withConfiguration(ProjectConfiguration()).launch() }69      numberOfTestsRunShouldBe(9)70   }71   test("filters a specific class and test") {72      withSystemProperties(73         mapOf(74            KotestEngineProperties.filterSpecs to "*NearFutureSciFiTests",75            KotestEngineProperties.filterTests to "Daedalus*"76         )77      ) { TestEngineLauncher().withClasses(testSuite).withConfiguration(ProjectConfiguration()).launch() }78      numberOfTestsRunShouldBe(1)79   }80   test("filters a test name with spaces") {81      withSystemProperties(82         mapOf(83            KotestEngineProperties.filterSpecs to "",84            KotestEngineProperties.filterTests to "trek tests*"85         )86      ) { TestEngineLauncher().withClasses(testSuite).withConfiguration(ProjectConfiguration()).launch() }87      numberOfTestsRunShouldBe(3)88   }89   test("filters all classes in a package") {90      withSystemProperties(91         mapOf(92            KotestEngineProperties.filterSpecs to "com.sksamuel.kotest.engine.interceptors.filters1.*",93            KotestEngineProperties.filterTests to ""94         )95      ) { TestEngineLauncher().withClasses(testSuite).withConfiguration(ProjectConfiguration()).launch() }96      numberOfTestsRunShouldBe(2)97   }98   test("filters nested tests in a context") {99      withSystemProperties(100         mapOf(101            KotestEngineProperties.filterSpecs to "",102            KotestEngineProperties.filterTests to "expanse tests*"103         )104      ) { TestEngineLauncher().withClasses(testSuite).withConfiguration(ProjectConfiguration()).launch() }105      numberOfTestsRunShouldBe(4)106   }107   test("filter tests using prefix and suffix wildcard") {108      withSystemProperties(109         mapOf(110            KotestEngineProperties.filterSpecs to "",111            KotestEngineProperties.filterTests to "*anse tes*"112         )113      ) { TestEngineLauncher().withClasses(testSuite).withConfiguration(ProjectConfiguration()).launch() }114      numberOfTestsRunShouldBe(4)115   }116   test("filter tests with prefix wildcard") {117      withSystemProperties(118         mapOf(119            KotestEngineProperties.filterSpecs to "",120            KotestEngineProperties.filterTests to "*BC-304"121         )122      ) { TestEngineLauncher().withClasses(testSuite).withConfiguration(ProjectConfiguration()).launch() }123      numberOfTestsRunShouldBe(2)124      testsRunShouldBe("Daedalus BC-304", "Odyssey BC-304")125   }126})127private class DistantFutureSciFiTests : FunSpec({128   context("trek tests") {129      test("Enterprise NCC-1701") { testAndIncrementCounter() }130      test("Excelsior NCC-2000") { testAndIncrementCounter() }131      test("Defiant NX-74205") { testAndIncrementCounter() }132   }133   context("expanse tests") {134      test("MCRN Donnager") { testAndIncrementCounter() }135      test("Rocinante") { testAndIncrementCounter() }136      test("UNN Arboghast") { testAndIncrementCounter() }...

Full Screen

Full Screen

IgnoredTestReasonTest.kt

Source:IgnoredTestReasonTest.kt Github

copy

Full Screen

...5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.core.spec.style.FunSpec7import io.kotest.core.spec.style.ShouldSpec8import io.kotest.core.test.Enabled9import io.kotest.engine.TestEngineLauncher10import io.kotest.engine.listener.CollectingTestEngineListener11import io.kotest.matchers.shouldBe12class IgnoredTestReasonTest : FunSpec() {13   init {14      test("enabledOrReasonIf should report the reason for skipping") {15         val collector = CollectingTestEngineListener()16         TestEngineLauncher(collector)17            .withClasses(EnabledOrReasonIfSpec::class)18            .launch()19         collector.tests.toList().first().second.reasonOrNull shouldBe "wobble"20      }21      test("EnabledExtension should report the reason for skipping") {22         val ext = object : EnabledExtension {23            override suspend fun isEnabled(descriptor: Descriptor): Enabled = Enabled.disabled("wibble")24         }25         val c = ProjectConfiguration().apply { registry.add(ext) }26         val collector = CollectingTestEngineListener()27         TestEngineLauncher(collector)28            .withClasses(MyFunSpec::class)29            .withConfiguration(c)30            .launch()31         collector.tests.toList().first().second.reasonOrNull shouldBe "wibble"32      }33      test("xdisabled in fun spec should report the reason for skipping") {34         val collector = CollectingTestEngineListener()35         TestEngineLauncher(collector)36            .withClasses(XReasonFunSpec::class)37            .launch()38         collector.tests.toList().first().second.reasonOrNull shouldBe "Disabled by xmethod"39      }40      test("xdisabled in describe spec should report the reason for skipping") {41         val collector = CollectingTestEngineListener()42         TestEngineLauncher(collector)43            .withClasses(XReasonDescribeSpec::class)44            .launch()45         collector.tests.toList().first().second.reasonOrNull shouldBe "Disabled by xmethod"46      }47      test("xdisabled in should spec should report the reason for skipping") {48         val collector = CollectingTestEngineListener()49         TestEngineLauncher(collector)50            .withClasses(XReasonShouldSpec::class)51            .launch()52         collector.tests.toList().first().second.reasonOrNull shouldBe "Disabled by xmethod"53      }54      test("enabled should report some reason for skipping") {55         val collector = CollectingTestEngineListener()56         TestEngineLauncher(collector)57            .withClasses(EnabledSpec::class)58            .launch()59         collector.tests.toList().first().second.reasonOrNull shouldBe "Disabled by enabled flag in config"60      }61      test("enabledIf should report some reason for skipping") {62         val collector = CollectingTestEngineListener()63         TestEngineLauncher(collector)64            .withClasses(EnabledIfSpec::class)65            .launch()66         collector.tests.toList().first().second.reasonOrNull shouldBe "Disabled by enabledIf flag in config"67      }68      test("bang should report some reason for skipping") {69         val collector = CollectingTestEngineListener()70         TestEngineLauncher(collector)71            .withClasses(BangSpec::class)72            .launch()73         collector.tests.toList().first().second.reasonOrNull shouldBe "Disabled by bang"74      }75   }76}77private class BangSpec : FunSpec() {78   init {79      test("!a") {80         throw RuntimeException()81      }82   }83}84private class EnabledSpec : FunSpec() {...

Full Screen

Full Screen

ActionTest.kt

Source:ActionTest.kt Github

copy

Full Screen

...11import io.kotest.core.spec.style.AnnotationSpec12import io.kotest.core.spec.style.BehaviorSpec13import io.kotest.core.spec.style.DescribeSpec14import io.kotest.core.test.TestScope15import io.kotest.engine.TestEngineLauncher16import io.kotest.engine.listener.CollectingTestEngineListener17import io.kotest.matchers.shouldBe18import io.mockk.mockk19private val reportScreen = ReportScreen("test report")20private val actionExecutor = AndroidExecutor(21    "serial", mockk(relaxed = true), mockk(relaxed = true),22    mockk(relaxed = true), mockk(relaxed = true),23)24private const val IMAGE_PREFIX = "prefix"25private open class ActionTestSpec(action: Action, reportScreen: ReportScreen) : DescribeSpec({26    describe(action.title()) {27        actionExecutor.imagePrefix = IMAGE_PREFIX28        action.runAction(29            actionExecutor,30            reportScreen,31            true,32        )33    }34})35private class ActionTestData(36    val name: String,37    val action: Action,38    val reportAction: ReportAction,39    val reportScreenNumberCheck: suspend TestScope.() -> Unit,40    val reportScreenModelCheck: suspend TestScope.() -> Unit,41)42private val data = listOf(43    ActionTestData(44        "Clear app data",45        Action.ClearAppData,46        Common(0, "Clear app data", 0, 4),47        {48            reportScreen.common.size shouldBe 149        },50        {51            val actualCommon = reportScreen.common[0]52            actualCommon.name shouldBe "Clear app data"53        }54    ),55    ActionTestData(56        "Take screenshot",57        Action.TakeScreenshot("name"),58        Screenshot(1, "name", 0, 4, "prefix", "path"),59        {60            reportScreen.screenshots.size shouldBe 161        },62        {63            val actualCommon = reportScreen.screenshots[0]64            actualCommon.name shouldBe "Take screenshot"65        }66    ),67    ActionTestData(68        "Take gfxinfo",69        Action.TakeGfxInfo,70        GfxInfo(0, "name", 0, 4, emptyMap()),71        {72            reportScreen.gfxInfo.size shouldBe 173        },74        {75            val actualCommon = reportScreen.gfxInfo[0]76            actualCommon.name shouldBe "Take gfxinfo"77        }78    ),79    ActionTestData(80        "Take memory allocation",81        Action.TakeMemoryAllocation,82        Memory(0, "name", 0, 4, emptyMap()),83        {84            reportScreen.memory.size shouldBe 185        },86        {87            val actualCommon = reportScreen.memory[0]88            actualCommon.name shouldBe "Take memory allocation"89        }90    ),91)92class ActionTest : BehaviorSpec({93    @AnnotationSpec.BeforeEach94    fun beforeTest() {95        reportScreen.common.clear()96        reportScreen.screenshots.clear()97        reportScreen.gfxInfo.clear()98        reportScreen.memory.clear()99    }100    data.forEach { actionTestData ->101        Given("Action ${actionTestData.action.title()}") {102            val collector = CollectingTestEngineListener()103            val projectConfiguration = ProjectConfiguration()104            When("execute action") {105                val ref = SpecRef.Function({106                    ActionTestSpec(actionTestData.action, reportScreen)107                }, ActionTestSpec::class)108                TestEngineLauncher(collector, projectConfiguration, emptyList(), listOf(ref), null)109                    .withExtensions()110                    .launch()111                Then("check test name") {112                    collector.result(actionTestData.name)?.isSuccess shouldBe true113                }114                Then("check report", actionTestData.reportScreenNumberCheck)115                Then("check model", actionTestData.reportScreenModelCheck)116            }117        }118    }119})...

Full Screen

Full Screen

launcher.kt

Source:launcher.kt Github

copy

Full Screen

...5import io.kotest.core.descriptors.toDescriptor6import io.kotest.core.filter.TestFilter7import io.kotest.core.filter.TestFilterResult8import io.kotest.core.spec.Spec9import io.kotest.engine.TestEngineLauncher10import io.kotest.engine.listener.TestEngineListener11import io.kotest.framework.discovery.Discovery12import io.kotest.framework.discovery.DiscoveryRequest13import io.kotest.framework.discovery.DiscoveryResult14import io.kotest.framework.discovery.DiscoverySelector15import kotlin.reflect.KClass16/**17 * Creates a [TestEngineLauncher] to be used to launch the test engine.18 */19internal fun setupLauncher(20   args: LauncherArgs,21   listener: TestEngineListener,22): Result<TestEngineLauncher> = runCatching {23   val specClass = args.spec?.let { (Class.forName(it) as Class<Spec>).kotlin }24   val (specs, _, error) = specs(specClass, args.packageName)25   val filter = if (args.testpath == null || specClass == null) null else {26      TestPathTestCaseFilter(args.testpath, specClass)27   }28   if (error != null) throw error29   TestEngineLauncher(listener)30      .withExtensions(listOfNotNull(filter))31      .withTagExpression(args.tagExpression?.let { TagExpression(it) })32      .withClasses(specs)33}34/**35 * Returns the spec classes to execute by using an FQN class name, a package scan,36 * or a full scan.37 */38private fun specs(specClass: KClass<out Spec>?, packageName: String?): DiscoveryResult {39   // if the spec class was null, then we perform discovery to locate all the classes40   // otherwise that specific spec class is used41   return when (specClass) {42      null -> scan(packageName)43      else -> DiscoveryResult(listOf(specClass), emptyList(), null)...

Full Screen

Full Screen

LateRootTestDefinitionTest.kt

Source:LateRootTestDefinitionTest.kt Github

copy

Full Screen

...7import io.kotest.core.spec.style.FreeSpec8import io.kotest.core.spec.style.FunSpec9import io.kotest.core.spec.style.ShouldSpec10import io.kotest.core.spec.style.scopes.addTest11import io.kotest.engine.TestEngineLauncher12import io.kotest.engine.listener.CollectingTestEngineListener13import io.kotest.matchers.types.shouldBeInstanceOf14@Description("Tests that a spec cannot define root tests after the spec has been instantiated")15class LateRootTestDefinitionTest : FunSpec() {16   init {17      test("expect spec") {18         val listener = CollectingTestEngineListener()19         TestEngineLauncher(listener)20            .withClasses(ExpectSpecWithExtraRootTests::class)21            .launch()22         listener.result("foo")!!.errorOrNull!!.shouldBeInstanceOf<InvalidDslException>()23      }24      test("feature spec") {25         val listener = CollectingTestEngineListener()26         TestEngineLauncher(listener)27            .withClasses(FeatureSpecWithExtraRootTests::class)28            .launch()29         listener.result("foo")!!.errorOrNull!!.shouldBeInstanceOf<InvalidDslException>()30      }31      test("free spec") {32         val listener = CollectingTestEngineListener()33         TestEngineLauncher(listener)34            .withClasses(FreeSpecWithExtraRootTests::class)35            .launch()36         listener.result("foo")!!.errorOrNull!!.shouldBeInstanceOf<InvalidDslException>()37      }38      test("fun spec") {39         val listener = CollectingTestEngineListener()40         TestEngineLauncher(listener)41            .withClasses(FunSpecWithExtraRootTests::class)42            .launch()43         listener.result("foo")!!.errorOrNull!!.shouldBeInstanceOf<InvalidDslException>()44      }45      test("should spec") {46         val listener = CollectingTestEngineListener()47         TestEngineLauncher(listener)48            .withClasses(ShouldSpecWithExtraRootTests::class)49            .launch()50         listener.result("foo")!!.errorOrNull!!.shouldBeInstanceOf<InvalidDslException>()51      }52   }53}54private class FreeSpecWithExtraRootTests : FreeSpec() {55   init {56      "foo" {57         this@FreeSpecWithExtraRootTests.addTest(TestName("bar"), false, null) { }58      }59   }60}61private class FunSpecWithExtraRootTests : FunSpec() {...

Full Screen

Full Screen

UnfinishedTestDefinitionTest.kt

Source:UnfinishedTestDefinitionTest.kt Github

copy

Full Screen

...4import io.kotest.core.spec.style.FeatureSpec5import io.kotest.core.spec.style.FunSpec6import io.kotest.core.spec.style.ShouldSpec7import io.kotest.core.spec.style.scopes.TestDslState8import io.kotest.engine.TestEngineLauncher9import io.kotest.engine.listener.NoopTestEngineListener10import io.kotest.inspectors.forAtLeastOne11import io.kotest.matchers.string.shouldContain12class UnfinishedTestDefinitionTest : FunSpec() {13   init {14      afterEach {15         TestDslState.reset()16      }17      test("fun spec") {18         val result = TestEngineLauncher(NoopTestEngineListener)19            .withClasses(FunSpecUnfinishedTestDefinitionTest::class)20            .launch()21         result.errors.forAtLeastOne { it.message!!.shouldContain("unfinished test") }22      }23      test("describe spec") {24         val result = TestEngineLauncher(NoopTestEngineListener)25            .withClasses(DescribeSpecUnfinishedTestDefinitionTest::class)26            .launch()27         result.errors.forAtLeastOne { it.message!!.shouldContain("unfinished it") }28      }29      test("should spec") {30         val result = TestEngineLauncher(NoopTestEngineListener)31            .withClasses(ShouldSpecUnfinishedTestDefinitionTest::class)32            .launch()33         result.errors.forAtLeastOne { it.message!!.shouldContain("unfinished should") }34      }35      test("feature spec") {36         val result = TestEngineLauncher(NoopTestEngineListener)37            .withClasses(FeatureSpecUnfinishedTestDefinitionTest::class)38            .launch()39         result.errors.forAtLeastOne { it.message!!.shouldContain("unfinished scenario") }40      }41      test("expect spec") {42         val result = TestEngineLauncher(NoopTestEngineListener)43            .withClasses(ExpectSpecUnfinishedTestDefinitionTest::class)44            .launch()45         result.errors.forAtLeastOne { it.message!!.shouldContain("unfinished expect") }46      }47   }48}49private class FunSpecUnfinishedTestDefinitionTest : FunSpec({50   context("context") {51      test("unfinished test")52   }53})54private class FeatureSpecUnfinishedTestDefinitionTest : FeatureSpec({55   feature("feature") {56      scenario("unfinished scenario")...

Full Screen

Full Screen

KotestUnit.kt

Source:KotestUnit.kt Github

copy

Full Screen

2import io.kotest.core.descriptors.toDescriptor3import io.kotest.core.spec.Spec4import io.kotest.core.test.TestCase5import io.kotest.core.test.TestResult6import io.kotest.engine.TestEngineLauncher7import io.kotest.engine.listener.AbstractTestEngineListener8import kotlinx.coroutines.runBlocking9import org.pitest.testapi.Description10import org.pitest.testapi.ResultCollector11import org.pitest.testapi.TestUnit12import kotlin.reflect.KClass13class KotestUnit(val klass: KClass<out Spec>) : TestUnit {14   override fun getDescription(): Description = Description(klass.toDescriptor().path().value, klass.java)15   override fun execute(rc: ResultCollector) = runBlocking<Unit> {16      val listener = object : AbstractTestEngineListener() {17         private val started = mutableSetOf<io.kotest.core.descriptors.Descriptor.TestDescriptor>()18         private val completed = mutableSetOf<io.kotest.core.descriptors.Descriptor.TestDescriptor>()19         override suspend fun testStarted(testCase: TestCase) {20            if (started.add(testCase.descriptor))21               rc.notifyStart(Description(testCase.descriptor.path().value, klass.java))22         }23         override suspend fun testFinished(testCase: TestCase, result: TestResult) {24            val desc = Description(testCase.descriptor.path().value, klass.java)25            if (completed.add(testCase.descriptor)) {26               when (result.errorOrNull) {27                  null -> rc.notifyEnd(desc)28                  else -> rc.notifyEnd(desc, result.errorOrNull)29               }30            }31         }32      }33      TestEngineLauncher()34         .withListener(listener)35         .withClasses(klass)36         .launch()37   }38}...

Full Screen

Full Screen

TestEngineLauncher

Using AI Code Generation

copy

Full Screen

1val launcher = TestEngineLauncher()2val listener = object : TestEngineListener {3override fun engineStarted(classes: List<KClass<out Spec>>) {4println("Engine started")5}6override fun engineFinished(t: List<Throwable>) {7println("Engine finished")8}9override fun specStarted(kclass: KClass<out Spec>) {10println("Spec started: ${kclass.simpleName}")11}12override fun specFinished(kclass: KClass<out Spec>, t: Throwable?) {13println("Spec finished: ${kclass.simpleName}")14}15override fun testStarted(testCase: TestCase) {16println("Test started: ${testCase.description.name}")17}18override fun testFinished(testCase: TestCase, result: TestResult) {19println("Test finished: ${testCase.description.name}")20}21}22launcher.withListener(listener)23launcher.execute()24}25}26val launcher = TestEngineLauncher()27val result = launcher.execute()28println("Specs: ${result.specs}")29println("Tests: ${result.tests}")30println("Success: ${result.success}")31println("Failures: ${result.failures}")32println("Errors: ${result.errors}")33println("Ignored: ${result.ignored}")34println("Skipped: ${result.skipped}")35val launcher = TestEngineLauncher()

Full Screen

Full Screen

TestEngineLauncher

Using AI Code Generation

copy

Full Screen

1val launcher = TestEngineLauncher()2launcher.registerListener(object : TestEngineListener {3override fun engineStarted(classes: List<KClass<*>>) {4println(“Engine started”)5}6override fun engineFinished(t: List<Throwable>) {7println(“Engine finished”)8}9override fun specStarted(kclass: KClass<*>) {10println(“Spec started : ${kclass.simpleName}”)11}12override fun specFinished(kclass: KClass<*>, t: Throwable?) {13println(“Spec finished : ${kclass.simpleName}”)14}15override fun testStarted(testCase: TestCase) {16println(“Test started : ${testCase.description}”)17}18override fun testFinished(testCase: TestCase, result: TestResult) {19println(“Test finished : ${testCase.description}”)20}21})22launcher.execute(listOf(MySpec::class))23launcher.execute()24val launcher = TestEngineLauncher()25launcher.registerListener(object : TestEngineListener {26override fun engineStarted(classes: List<KClass<*>>) {27println(“Engine started”)28}29override fun engineFinished(t: List<Throwable>) {30println(“Engine finished”)31}32override fun specStarted(kclass: KClass<*>) {33println(“Spec started : ${kclass.simpleName}”)34}35override fun specFinished(kclass: KClass<*>, t: Throwable?) {36println(“Spec finished : ${kclass.simpleName}”)37}38override fun testStarted(testCase: TestCase) {39println(“Test started : ${testCase.description}”)40}41override fun testFinished(testCase: TestCase, result: TestResult) {42println(“Test finished : ${testCase.description}”)43}44})45launcher.execute(listOf(MySpec::class))46launcher.execute()

Full Screen

Full Screen

TestEngineLauncher

Using AI Code Generation

copy

Full Screen

1val launcher = TestEngineLauncher()2launcher.withClasses(testClass)3launcher.withListener(listener)4launcher.execute()5val launcher = TestEngineLauncher()6launcher.withClasses(testClass)7launcher.withListener(listener)8launcher.execute()9val launcher = TestEngineLauncher()10launcher.withClasses(testClass)11launcher.withListener(listener)12launcher.execute()13val launcher = TestEngineLauncher()14launcher.withClasses(testClass)15launcher.withListener(listener)16launcher.execute()17val launcher = TestEngineLauncher()18launcher.withClasses(testClass)19launcher.withListener(listener)20launcher.execute()21val launcher = TestEngineLauncher()22launcher.withClasses(testClass)23launcher.withListener(listener)24launcher.execute()25val launcher = TestEngineLauncher()26launcher.withClasses(testClass)27launcher.withListener(listener)28launcher.execute()29val launcher = TestEngineLauncher()30launcher.withClasses(testClass)31launcher.withListener(listener)32launcher.execute()33val launcher = TestEngineLauncher()34launcher.withClasses(testClass)35launcher.withListener(listener)36launcher.execute()37val launcher = TestEngineLauncher()38launcher.withClasses(testClass)39launcher.withListener(listener)40launcher.execute()41val launcher = TestEngineLauncher()42launcher.withClasses(testClass)43launcher.withListener(listener)44launcher.execute()45val launcher = TestEngineLauncher()46launcher.withClasses(testClass)47launcher.withListener(listener)48launcher.execute()49val launcher = TestEngineLauncher()50launcher.withClasses(testClass)51launcher.withListener(listener)52launcher.execute()53val launcher = TestEngineLauncher()54launcher.withClasses(testClass)55launcher.withListener(listener

Full Screen

Full Screen

TestEngineLauncher

Using AI Code Generation

copy

Full Screen

1val launcher = TestEngineLauncher()2launcher.withClasses(listOf(MySpec::class))3launcher.withListener(object : TestEngineListener {4override fun engineFinished(t: List<TestCase>) {5println("Engine finished")6}7override fun engineStarted(classes: List<KClass<out Spec>>) {8println("Engine started")9}10override fun specFinished(kclass: KClass<out Spec>, t: List<TestCase>) {11println("Spec finished: ${kclass.simpleName}")12}13override fun specStarted(kclass: KClass<out Spec>) {14println("Spec started: ${kclass.simpleName}")15}16override fun testFinished(testCase: TestCase, result: TestResult) {17println("Test finished: ${testCase.description.name} - ${result.status}")18}19override fun testIgnored(testCase: TestCase, reason: String?) {20println("Test ignored: ${testCase.description.name} - $reason")21}22override fun testStarted(testCase: TestCase) {23println("Test started: ${testCase.description.name}")24}25})26launcher.execute()27val launcher = TestEngineLauncher()28launcher.withClasses(listOf(MySpec::class))29launcher.withListener(object : TestEngineListener {30override fun engineFinished(t: List<TestCase>) {31println("Engine finished")32}33override fun engineStarted(classes: List<KClass<out Spec>>) {34println("Engine started")35}36override fun specFinished(kclass: KClass<out Spec>, t: List<TestCase>) {37println("Spec finished: ${kclass.simpleName}")38}39override fun specStarted(kclass: KClass<out Spec>) {40println("Spec started: ${kclass.simpleName}")41}42override fun testFinished(testCase: TestCase, result: TestResult) {43println("Test finished: ${testCase.description.name} - ${result.status}")44}45override fun testIgnored(testCase: TestCase, reason: String?) {46println("Test ignored: ${testCase.description.name} - $reason")47}48override fun testStarted(testCase: TestCase) {49println("Test started: ${testCase.description.name}")50}51})52launcher.execute()53val launcher = TestEngineLauncher()54launcher.withClasses(listOf(MySpec::class))55launcher.withListener(object : TestEngineListener {56override fun engineFinished(t: List<TestCase>) {57println("Engine finished")58}59override fun engineStarted(classes: List<KClass

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