Best Kotest code snippet using io.kotest.engine.TestEngineLauncher.testSuite
TestEngineLauncher.kt
Source:TestEngineLauncher.kt
...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}...
SystemPropertyFiltersTests.kt
Source:SystemPropertyFiltersTests.kt
...23}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() }...
TestEngine.kt
Source:TestEngine.kt
1package io.kotest.engine2import io.kotest.common.ExperimentalKotest3import io.kotest.common.KotestInternal4import io.kotest.common.Platform5import 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}...
testSuite
Using AI Code Generation
1import io.kotest.core.config.Configuration2import io.kotest.core.spec.style.AnnotationSpec3import io.kotest.core.spec.style.FunSpec4import io.kotest.engine.TestEngineLauncher5import io.kotest.engine.listener.TestEngineListener6import io.kotest.engine.listener.TestEngineListenerAdapter7import io.kotest.engine.listener.TestListener8import io.kotest.engine.listener.TestListenerAdapter9import io.kotest.engine.spec.SpecExecutor10import io.kotest.engine.spec.SpecExecutorListener11import io.kotest.engine.spec.SpecExecutorListenerAdapter12import io.kotest.engine.spec.materializeAndOrderRootTests13import io.kotest.engine.spec.toSpecs14import io.kotest.engine.test.TestCaseExecutor15import io.kotest.engine.test.TestCaseExecutorListener16import io.kotest.engine.test.TestCaseExecutorListenerAdapter17import io.kotest.engine.test.materializeAndOrderRootTests18import io.kotest.engine.test.toTestCases19import io.kotest.engine.test.toTestCases20import io.kotest.mpp.log21import io.kotest.mpp.sysprop22import io.kotest.mpp.timeInMillis23import io.kotest.core.spec.Spec24import io.kotest.core.spec.style.AnnotationSpec25import io.kotest.core.spec.style.FunSpec26import io.kotest.core.test.TestCase27import io.kotest.core.test.TestResult28import io.kotest.core.test.TestType29import io.kotest.engine.listener.TestEngineListener30import io.kotest.engine.listener.TestEngineListenerAdapter31import io.kotest.engine.listener.TestListener32import io.kotest.engine.listener.TestListenerAdapter33import io.kotest.engine.spec.SpecExecutor34import io.kotest.engine.spec.SpecExecutorListener35import io.kotest.engine.spec.SpecExecutorListenerAdapter36import io.kotest.engine.spec.materializeAndOrderRootTests37import io.kotest.engine.spec.toSpecs38import io.kotest.engine.test.TestCaseExecutor39import io.kotest.engine.test.TestCaseExecutorListener40import io.kotest.engine.test.TestCaseExecutorListenerAdapter41import io.kotest.engine.test.materializeAndOrderRootTests42import io.kotest.engine.test.toTestCases43import io.kotest.engine.test.toTestCases44import io.kotest.mpp.log45import io.kotest.mpp.sysprop46import io.kotest
testSuite
Using AI Code Generation
1import io.kotest.core.config.AbstractProjectConfig2import io.kotest.core.spec.style.StringSpec3import io.kotest.engine.TestEngineLauncher4import io.kotest.engine.config.AbstractEngineConfig5import io.kotest.engine.config.EngineConfig6import io.kotest.engine.config.EngineSystemProperties7import io.kotest.engine.config.ProjectConfig8import io.kotest.engine.config.Property9import io.kotest.engine.config.RuntimeConfig10import io.kotest.engine.config.RuntimeConfigRegistry11import io.kotest.engine.config.TestSuite12import io.kotest.engine.config.TestSuiteFilter13import io.kotest.engine.config.TestSuiteOptions14import io.kotest.engine.config.TestSuiteOptionsBuilder15import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.default16import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.spec17import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.test18import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.testCase19import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.testContainer20import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.testFactory21import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.testInstance22import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.testInstanceFactory23import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.testWithConfig24import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.xdisabled25import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.xtest26import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.xtestCase27import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.xtestContainer28import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.xtestFactory29import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.xtestInstance30import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.xtestInstanceFactory31import io.kotest.engine.config.TestSuiteOptionsBuilder.Companion.xtestWithConfig32import io.kotest.engine.config.defaultProjectConfig33import io.kotest.engine.config.defaultRuntimeConfig34import io.kotest.engine.config.defaultRuntimeConfigWithArgs35import io.kotest.engine.config.defaultRuntimeConfigWithArgsAndProperties36import io.kotest.engine.config.defaultRuntimeConfigWithProperties37import io.kotest.engine.config.defaultRuntimeConfigWithSystemProperties38import io.kotest.engine.config.defaultRuntimeConfigWith
testSuite
Using AI Code Generation
1val launcher = TestEngineLauncher()2val result = launcher.withClasses(ExampleTest::class).launch()3val launcher = TestEngineLauncher()4val result = launcher.withClasses(ExampleTest::class).launch()5val launcher = TestEngineLauncher()6val result = launcher.withClasses(ExampleTest::class).launch()7val launcher = TestEngineLauncher()8val result = launcher.withClasses(ExampleTest::class).launch()9val launcher = TestEngineLauncher()10val result = launcher.withClasses(ExampleTest::class).launch()11val launcher = TestEngineLauncher()12val result = launcher.withClasses(ExampleTest::class).launch()13val launcher = TestEngineLauncher()14val result = launcher.withClasses(ExampleTest::class).launch()15val launcher = TestEngineLauncher()16val result = launcher.withClasses(ExampleTest::class).launch()17val launcher = TestEngineLauncher()18val result = launcher.withClasses(ExampleTest::class).launch()19val launcher = TestEngineLauncher()20val result = launcher.withClasses(ExampleTest::class).launch()21val launcher = TestEngineLauncher()22val result = launcher.withClasses(ExampleTest::class).launch()23val launcher = TestEngineLauncher()24val result = launcher.withClasses(ExampleTest::class).launch()25val launcher = TestEngineLauncher()26val result = launcher.withClasses(ExampleTest::class).launch()
testSuite
Using AI Code Generation
1import io.kotest.core.spec.style.FunSpec2class MySpec : FunSpec({3 test("some test") {4 }5})6import io.kotest.core.spec.style.FunSpec7import io.kotest.engine.TestEngineLauncher8import io.kotest.engine.listener.PrintTestEngineListener9fun main() {10 TestEngineLauncher(PrintTestEngineListener)11 .withClasses(MySpec::class)12 .launch()13}14import io.kotest.core.spec.style.FunSpec15class MySpec : FunSpec({16 test("some test") {17 }18})19import io.kotest.core.spec.style.FunSpec20import io.kotest.engine.TestEngineLauncher21import io.kotest.engine.listener.PrintTestEngineListener22fun main() {23 TestEngineLauncher(PrintTestEngineListener)24 .testEngine()25 .launch()26}27import io.kotest.core.spec.style.FunSpec28class MySpec : FunSpec({29 test("some test") {30 }31})32import io.kotest.core.spec.style.FunSpec33import io.kotest.engine.TestEngineLauncher34import io.kotest.engine.listener.PrintTestEngineListener35fun main() {36 TestEngineLauncher(PrintTestEngineListener)37 .testEngine()38 .launch()39}40import io.kotest.core.spec.style.FunSpec41class MySpec : FunSpec({42 test("some test") {43 }44})45import io.kotest.core.spec.style.FunSpec46import io.kotest.engine.TestEngineLauncher47import io.kotest.engine.listener.PrintTestEngineListener48fun main() {49 TestEngineLauncher(PrintTestEngineListener)50 .testEngine()51 .launch()52}53import io.kotest.core.spec.style.FunSpec54class MySpec : FunSpec({55 test("some test") {56 }57})58import io.kotest.core.spec.style.FunSpec59import io.kotest.engine.TestEngineLauncher60import io
testSuite
Using AI Code Generation
1val launcher = TestEngineLauncher()2.launch(3testSuite(4test("test 1") {5println("test 1")6},7test("test 2") {8println("test 2")9}10println("Tests executed: ${results.tests}")11println("Tests failed: ${results.failures}")12}13}
testSuite
Using AI Code Generation
1val launcher = TestEngineLauncher()2.withClasses(MyTestClass::class)3.testSuite()4println(result)5}6}7val launcher = TestEngineLauncher()8.withClasses(MyTestClass::class)9.testSuite()10println(result)11}12TestSuiteResult(status=Success, tests=1, errors=0, failures=0, skipped=0, ignored=0)
testSuite
Using AI Code Generation
1testSuite {2 testSuite {3 specs = listOf(4 config = ProjectConfigExample()5 }6}7testSuite {8 testEngine {9 specs = listOf(10 config = ProjectConfigExample()11 }12}13testSuite {14 testEngine {15 specs = listOf(16 config = ProjectConfigExample()17 }18}19testEngine {
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!!