Best Kotest code snippet using io.kotest.engine.test.TestCaseExecutor
TestCaseExecutorTest.kt
Source:TestCaseExecutorTest.kt
...9import io.kotest.engine.concurrency.NoopCoroutineDispatcherFactory10import io.kotest.engine.extensions.ExtensionException11import io.kotest.engine.spec.Materializer12import io.kotest.engine.test.TestCaseExecutionListener13import io.kotest.engine.test.TestCaseExecutor14import io.kotest.engine.test.interceptors.TestTimeoutException15import io.kotest.matchers.booleans.shouldBeTrue16import io.kotest.matchers.shouldBe17import io.kotest.matchers.types.shouldBeInstanceOf18import kotlinx.coroutines.DelicateCoroutinesApi19import kotlinx.coroutines.GlobalScope20import kotlinx.coroutines.delay21import kotlin.coroutines.CoroutineContext22import kotlin.time.Duration.Companion.milliseconds23@ExperimentalKotest24@DelicateCoroutinesApi25class TestCaseExecutorTest : FunSpec({26 fun context(testCase: TestCase) = object : TestScope {27 override val testCase: TestCase = testCase28 override suspend fun registerTestCase(nested: NestedTest) {}29 override val coroutineContext: CoroutineContext = GlobalScope.coroutineContext30 }31 test("test executor happy path") {32 var started = false33 var finished = false34 val listener = object : TestCaseExecutionListener {35 override suspend fun testStarted(testCase: TestCase) {36 started = true37 }38 override suspend fun testIgnored(testCase: TestCase, reason: String?) {}39 override suspend fun testFinished(testCase: TestCase, result: TestResult) {40 finished = true41 result.isSuccess shouldBe true42 }43 }44 val executor = TestCaseExecutor(listener, NoopCoroutineDispatcherFactory, ProjectConfiguration())45 val testCase = Materializer(ProjectConfiguration()).materialize(Tests()).first { it.name.testName == "a" }46 executor.execute(testCase, context(testCase)).isSuccess shouldBe true47 started shouldBe true48 finished shouldBe true49 }50 test("TestCaseExecutor should timeout a suspendable call") {51 var started = false52 var finished = false53 val listener = object : TestCaseExecutionListener {54 override suspend fun testStarted(testCase: TestCase) {55 started = true56 }57 override suspend fun testIgnored(testCase: TestCase, reason: String?) {}58 override suspend fun testFinished(testCase: TestCase, result: TestResult) {59 finished = true60 result.isError shouldBe true61 }62 }63 val executor = TestCaseExecutor(listener, NoopCoroutineDispatcherFactory, ProjectConfiguration())64 val testCase = Materializer(ProjectConfiguration()).materialize(Tests()).first { it.name.testName == "b" }65 val result = executor.execute(testCase, context(testCase))66 result.isError shouldBe true67 result.errorOrNull shouldBe TestTimeoutException(100.milliseconds, "b")68 started shouldBe true69 finished shouldBe true70 }71 test("TestCaseExecutor should invoke before test") {72 val executor = TestCaseExecutor(object : TestCaseExecutionListener {73 override suspend fun testStarted(testCase: TestCase) {}74 override suspend fun testIgnored(testCase: TestCase, reason: String?) {}75 override suspend fun testFinished(testCase: TestCase, result: TestResult) {}76 }, NoopCoroutineDispatcherFactory, ProjectConfiguration())77 val spec = BeforeTest()78 val testCase = Materializer(ProjectConfiguration()).materialize(spec).shuffled().first()79 executor.execute(testCase, context(testCase))80 spec.before.shouldBeTrue()81 }82 test("TestCaseExecutor should invoke after test") {83 val executor = TestCaseExecutor(object : TestCaseExecutionListener {84 override suspend fun testStarted(testCase: TestCase) {}85 override suspend fun testIgnored(testCase: TestCase, reason: String?) {}86 override suspend fun testFinished(testCase: TestCase, result: TestResult) {}87 }, NoopCoroutineDispatcherFactory, ProjectConfiguration())88 val spec = AfterTest()89 val testCase = Materializer(ProjectConfiguration()).materialize(spec).shuffled().first()90 executor.execute(testCase, context(testCase))91 spec.after.shouldBeTrue()92 }93 test("TestCaseExecutor should start/finish test with error if before-test throws") {94 var started = false95 var finished = false96 val executor = TestCaseExecutor(object : TestCaseExecutionListener {97 override suspend fun testStarted(testCase: TestCase) {98 started = true99 }100 override suspend fun testIgnored(testCase: TestCase, reason: String?) {}101 override suspend fun testFinished(testCase: TestCase, result: TestResult) {102 finished = true103 }104 }, NoopCoroutineDispatcherFactory, ProjectConfiguration())105 val testCase = Materializer(ProjectConfiguration()).materialize(BeforeTestWithException()).shuffled().first()106 val result = executor.execute(testCase, context(testCase))107 result.isError shouldBe true108 result.errorOrNull.shouldBeInstanceOf<ExtensionException.BeforeTestException>()109 started shouldBe true110 finished shouldBe true111 }112 test("TestCaseExecutor should start/finish test with error if after-test throws") {113 var started = false114 var finished = false115 val executor = TestCaseExecutor(object : TestCaseExecutionListener {116 override suspend fun testStarted(testCase: TestCase) {117 started = true118 }119 override suspend fun testIgnored(testCase: TestCase, reason: String?) {}120 override suspend fun testFinished(testCase: TestCase, result: TestResult) {121 finished = true122 }123 }, NoopCoroutineDispatcherFactory, ProjectConfiguration())124 val testCase = Materializer(ProjectConfiguration()).materialize(AfterTestWithException()).shuffled().first()125 val result = executor.execute(testCase, context(testCase))126 result.isError shouldBe true127 result.errorOrNull.shouldBeInstanceOf<ExtensionException.AfterTestException>()128 started shouldBe true129 finished shouldBe true...
ScriptExecutor.kt
Source:ScriptExecutor.kt
1//package io.kotest.engine.script2//3//import io.kotest.engine.test.TestCaseExecutor4//import io.kotest.core.plan.Descriptor5//import io.kotest.core.plan.toDescriptor6//import io.kotest.core.script.ScriptRuntime7//import io.kotest.core.test.NestedTest8//import io.kotest.core.test.TestCase9//import io.kotest.engine.test.TestCaseExecutionListener10//import io.kotest.core.test.testScope11//import io.kotest.core.test.TestResult12//import io.kotest.core.test.createTestName13//import io.kotest.engine.ExecutorExecutionContext14//import io.kotest.engine.events.Notifications15//import io.kotest.engine.listener.TestEngineListener16//import io.kotest.engine.test.names.DuplicateTestNameHandler17//import io.kotest.mpp.log18//import java.util.concurrent.ConcurrentHashMap19//import kotlin.coroutines.CoroutineContext20//import kotlin.coroutines.coroutineContext21//import kotlin.reflect.KClass22//import kotlin.script.templates.standard.ScriptTemplateWithArgs23//24///**25// * Handles the execution of a single [ScriptTemplateWithArgs] class.26// *27// * @param listener a listener that is notified of events in the spec lifecycle28// */29//class ScriptExecutor(private val listener: TestEngineListener) {30//31// private val results = ConcurrentHashMap<Descriptor.TestDescriptor, TestResult>()32// private val n = Notifications(listener)33//34// /**35// * Executes the given test [ScriptTemplateWithArgs].36// */37// suspend fun execute(kclass: KClass<out ScriptTemplateWithArgs>): Try<Unit> {38// log { "ScriptExecutor: execute [$kclass]" }39// ScriptRuntime.reset()40// val descriptor = Descriptor.fromScriptClass(kclass)41// return createInstance(kclass)42// .flatMap { n.specStarted(descriptor) }43// .flatMap { runTests(descriptor) }44// .onFailure { n.specFinished(descriptor, it, emptyMap()) }45// .onSuccess { n.specFinished(descriptor, null, results.toMap()) }46// }47//48//// /**49//// * Invokes the script by finding and executing the generated main method.50//// */51//// private suspend fun runScript(script: ScriptTemplateWithArgs): Try<Unit> = Try {52////// ScriptRuntime.reset()53////54////// BasicJvmScriptEvaluator().invoke(55////// KJvmCompiledScript(56////// null,57////// ScriptCompilationConfiguration.Default,58////// script.javaClass.name,59////// resultField = null,60////// compiledModule = KJvmCompiledModuleFromClassLoader(this.javaClass.classLoader),61////// ), ScriptEvaluationConfiguration()62////// )63////64//// //65//// //val main = script.javaClass.getMethod("main", Array<String>::class.java)66//// //log("ScriptExecutor: Invoking script main [$main]")67//// //main.invoke(null, emptyArray<String>())68//// }69//70// /**71// * Executes the tests registered with the script execution runtime.72// */73// private suspend fun runTests(descriptor: Descriptor.SpecDescriptor): Try<Unit> = Try {74// log { "ScriptExecutor: Executing tests from script" }75// ScriptRuntime.materializeRootTests(descriptor).forEach { testCase ->76// runTest(testCase, coroutineContext)77// }78// }79//80// /**81// * Creates an instance of the given [ScriptTemplateWithArgs] by delegating to the project constructors,82// * and notifies the [TestEngineListener] of the instantiation event.83// */84// private fun createInstance(kclass: KClass<out ScriptTemplateWithArgs>): Try<ScriptTemplateWithArgs> {85// log { "ScriptExecutor: Creating instance of $kclass" }86// return createAndInitializeScript(kclass, this.javaClass.classLoader)87// }88//89// private suspend fun runTest(90// testCase: TestCase,91// coroutineContext: CoroutineContext,92// ) {93// val testExecutor = TestCaseExecutor(object : TestCaseExecutionListener {94// override suspend fun testStarted(testCase: TestCase) {95// listener.testStarted(testCase.descriptor!!)96// }97//98// override suspend fun testIgnored(testCase: TestCase) {99// listener.testIgnored(testCase.descriptor!!, null)100// }101//102// override suspend fun testFinished(testCase: TestCase, result: TestResult) {103// listener.testFinished(testCase.descriptor!!, result)104// }105// }, ExecutorExecutionContext)106//107// val result = testExecutor.execute(testCase, Context(testCase, coroutineContext))...
SingleInstanceSpecRunner.kt
Source:SingleInstanceSpecRunner.kt
...11import io.kotest.engine.listener.TestEngineListener12import io.kotest.engine.spec.Materializer13import io.kotest.engine.spec.SpecExtensions14import io.kotest.engine.spec.SpecRunner15import io.kotest.engine.test.TestCaseExecutor16import io.kotest.engine.test.listener.TestCaseExecutionListenerToTestEngineListenerAdapter17import io.kotest.engine.test.scheduler.TestScheduler18import io.kotest.engine.test.scopes.DuplicateNameHandlingTestScope19import io.kotest.mpp.Logger20import io.kotest.mpp.bestName21import kotlinx.coroutines.coroutineScope22import java.util.concurrent.ConcurrentHashMap23import kotlin.coroutines.CoroutineContext24/**25 * Implementation of [SpecRunner] that executes all tests against the26 * same [Spec] instance. In other words, only a single instance of the spec class27 * is instantiated for all the test cases.28 */29@ExperimentalKotest30internal class SingleInstanceSpecRunner(31 listener: TestEngineListener,32 scheduler: TestScheduler,33 private val defaultCoroutineDispatcherFactory: CoroutineDispatcherFactory,34 private val configuration: ProjectConfiguration,35) : SpecRunner(listener, scheduler, configuration) {36 private val results = ConcurrentHashMap<TestCase, TestResult>()37 private val extensions = SpecExtensions(configuration.registry)38 private val logger = Logger(SingleInstanceSpecRunner::class)39 override suspend fun execute(spec: Spec): Result<Map<TestCase, TestResult>> {40 logger.log { Pair(spec::class.bestName(), "executing spec $spec") }41 suspend fun interceptAndRun(context: CoroutineContext) = runCatching {42 val rootTests = materializer.materialize(spec)43 logger.log { Pair(spec::class.bestName(), "Materialized root tests: ${rootTests.size}") }44 launch(spec) {45 logger.log { Pair(it.name.testName, "Executing test $it") }46 runTest(it, context, null)47 }48 }49 try {50 return coroutineScope {51 extensions.beforeSpec(spec)52 .flatMap { interceptAndRun(coroutineContext) }53 .flatMap { SpecExtensions(configuration.registry).afterSpec(spec) }54 .map { results }55 }56 } catch (e: Exception) {57 e.printStackTrace()58 throw e59 }60 }61 /**62 * A [TestScope] that runs discovered tests as soon as they are registered in the same spec instance.63 *64 * This implementation tracks fail fast if configured via TestCase config or globally.65 */66 inner class SingleInstanceTestScope(67 override val testCase: TestCase,68 override val coroutineContext: CoroutineContext,69 private val parentScope: SingleInstanceTestScope?,70 ) : TestScope {71 // set to true if we failed fast and should ignore further tests72 private var skipRemaining = false73 // in the single instance runner we execute each nested test as soon as they are registered74 override suspend fun registerTestCase(nested: NestedTest) {75 logger.log { Pair(testCase.name.testName, "Nested test case discovered '${nested}") }76 val nestedTestCase = Materializer(configuration).materialize(nested, testCase)77 if (skipRemaining) {78 logger.log { Pair(testCase.name.testName, "Skipping test due to fail fast") }79 listener.testIgnored(nestedTestCase, "Skipping test due to fail fast")80 } else {81 // if running this nested test results in an error, we won't launch anymore nested tests82 val result = runTest(nestedTestCase, coroutineContext, this@SingleInstanceTestScope)83 if (result.isErrorOrFailure) {84 if (testCase.config.failfast || configuration.projectWideFailFast) {85 logger.log { Pair(testCase.name.testName, "Test failed - setting skipRemaining = true") }86 skipRemaining = true87 parentScope?.skipRemaining = true88 }89 }90 }91 }92 }93 private suspend fun runTest(94 testCase: TestCase,95 coroutineContext: CoroutineContext,96 parentScope: SingleInstanceTestScope?,97 ): TestResult {98 val testExecutor = TestCaseExecutor(99 TestCaseExecutionListenerToTestEngineListenerAdapter(listener),100 defaultCoroutineDispatcherFactory,101 configuration,102 )103 val scope = DuplicateNameHandlingTestScope(104 configuration.duplicateTestNameMode,105 SingleInstanceTestScope(testCase, coroutineContext, parentScope)106 )107 val result = testExecutor.execute(testCase, scope)108 results[testCase] = result109 return result110 }111}...
TestCaseExecutor.kt
Source:TestCaseExecutor.kt
...36 * Uses a [TestCaseExecutionListener] to notify callers of events in the test lifecycle.37 *38 */39@OptIn(ExperimentalKotest::class)40class TestCaseExecutor(41 private val listener: TestCaseExecutionListener,42 private val defaultCoroutineDispatcherFactory: CoroutineDispatcherFactory = NoopCoroutineDispatcherFactory,43 private val configuration: ProjectConfiguration,44) {45 private val logger = Logger(TestCaseExecutor::class)46 suspend fun execute(testCase: TestCase, testScope: TestScope): TestResult {47 val timeMark = TimeSource.Monotonic.markNow()48 val interceptors = listOfNotNull(49 TestPathContextInterceptor,50 TestFinishedInterceptor(listener),51 InvocationCountCheckInterceptor,52 SupervisorScopeInterceptor,53 if (platform == Platform.JVM) coroutineDispatcherFactoryInterceptor(defaultCoroutineDispatcherFactory) else null,54 if (platform == Platform.JVM) coroutineErrorCollectorInterceptor() else null,55 TestCaseExtensionInterceptor(configuration.registry),56 EnabledCheckInterceptor(configuration),57 LifecycleInterceptor(listener, timeMark, configuration.registry),58 AssertionModeInterceptor,59 SoftAssertInterceptor(),...
TestTimeoutAfterTestListenerTest.kt
Source:TestTimeoutAfterTestListenerTest.kt
...11import io.kotest.core.test.TestType12import io.kotest.core.test.config.ResolvedTestConfig13import io.kotest.engine.concurrency.NoopCoroutineDispatcherFactory14import io.kotest.engine.test.NoopTestCaseExecutionListener15import io.kotest.engine.test.TestCaseExecutor16import io.kotest.engine.test.scopes.NoopTestScope17import io.kotest.matchers.shouldBe18import kotlinx.coroutines.DelicateCoroutinesApi19import kotlinx.coroutines.Dispatchers20import kotlinx.coroutines.delay21import kotlinx.coroutines.withContext22import java.util.concurrent.atomic.AtomicInteger23import kotlin.time.Duration.Companion.milliseconds24@DelicateCoroutinesApi25@Suppress("BlockingMethodInNonBlockingContext")26class TestTimeoutAfterTestListenerTest : FunSpec() {27 init {28 test("tests that timeout during a blocking operation should still run the 'after test' listeners").config(29 timeout = 10000.milliseconds,30 blockingTest = true,31 ) {32 val blockingCount = AtomicInteger(0)33 // this listener will flick the flag to true, so we know it ran34 val listener = object : AfterTestListener {35 override suspend fun afterTest(testCase: TestCase, result: TestResult) {36 blockingCount.incrementAndGet()37 }38 }39 val tc = TestCase(40 descriptor = TestTimeoutAfterTestListenerTest::class.toDescriptor().append("wibble"),41 name = TestName("wibble"),42 spec = this@TestTimeoutAfterTestListenerTest,43 test = { Thread.sleep(1000000) },44 source = sourceRef(),45 type = TestType.Container,46 parent = null,47 config = ResolvedTestConfig.default.copy(48 timeout = 1.milliseconds,49 extensions = listOf(listener),50 blockingTest = true51 ),52 )53 val executor = TestCaseExecutor(NoopTestCaseExecutionListener, NoopCoroutineDispatcherFactory, ProjectConfiguration())54 // needs to run on a separate thread, so we don't interrupt our own thread55 withContext(Dispatchers.IO) {56 executor.execute(tc, NoopTestScope(testCase, coroutineContext))57 }58 blockingCount.get() shouldBe 159 }60 test("tests which timeout during a suspending operation should still run the 'after test' listeners").config(61 timeout = 10000.milliseconds62 ) {63 val suspendingCount = AtomicInteger(0)64 // this listener will flick the flag to true, so we know it ran65 val listener = object : AfterTestListener {66 override suspend fun afterAny(testCase: TestCase, result: TestResult) {67 suspendingCount.incrementAndGet()68 }69 }70 val tc = TestCase(71 descriptor = TestTimeoutAfterTestListenerTest::class.toDescriptor().append("wobble"),72 name = TestName("wobble"),73 spec = this@TestTimeoutAfterTestListenerTest,74 test = { delay(1000000) },75 source = sourceRef(),76 type = TestType.Container,77 parent = null,78 config = ResolvedTestConfig.default.copy(79 timeout = 1.milliseconds,80 extensions = listOf(listener),81 blockingTest = false82 ),83 )84 val executor = TestCaseExecutor(NoopTestCaseExecutionListener, NoopCoroutineDispatcherFactory, ProjectConfiguration())85 // needs to run on a separate thread, so we don't interrupt our own thread86 withContext(Dispatchers.IO) {87 executor.execute(tc, NoopTestScope(testCase, coroutineContext))88 }89 suspendingCount.get() shouldBe 190 }91 }92}...
TestTimeoutTest.kt
Source:TestTimeoutTest.kt
...9import io.kotest.core.test.TestType10import io.kotest.core.test.config.ResolvedTestConfig11import io.kotest.engine.concurrency.NoopCoroutineDispatcherFactory12import io.kotest.engine.test.NoopTestCaseExecutionListener13import io.kotest.engine.test.TestCaseExecutor14import io.kotest.engine.test.scopes.NoopTestScope15import kotlinx.coroutines.DelicateCoroutinesApi16import kotlinx.coroutines.Dispatchers17import kotlinx.coroutines.delay18import kotlinx.coroutines.withContext19import kotlin.time.Duration.Companion.milliseconds20@DelicateCoroutinesApi21@Suppress("BlockingMethodInNonBlockingContext")22class TestTimeoutTest : FunSpec() {23 init {24 test("tests that timeout during a blocking operation should be interrupted").config(25 timeout = 10000.milliseconds,26 blockingTest = true,27 ) {28 val tc = TestCase(29 descriptor = TestTimeoutTest::class.toDescriptor().append("wibble"),30 name = TestName("wibble"),31 spec = this@TestTimeoutTest,32 test = { Thread.sleep(10000000) },33 source = sourceRef(),34 type = TestType.Container,35 parent = null,36 config = ResolvedTestConfig.default.copy(37 timeout = 1.milliseconds,38 blockingTest = true39 ),40 )41 val executor = TestCaseExecutor(NoopTestCaseExecutionListener, NoopCoroutineDispatcherFactory, ProjectConfiguration())42 // needs to run on a separate thread, so we don't interrupt our own thread43 withContext(Dispatchers.IO) {44 executor.execute(tc, NoopTestScope(testCase, coroutineContext))45 }46 }47 test("tests which timeout during a suspending operation should be cancelled").config(48 timeout = 10000.milliseconds49 ) {50 val tc = TestCase(51 descriptor = TestTimeoutTest::class.toDescriptor().append("wobble"),52 name = TestName("wobble"),53 spec = this@TestTimeoutTest,54 test = { delay(1000000) },55 source = sourceRef(),56 type = TestType.Container,57 parent = null,58 config = ResolvedTestConfig.default.copy(59 timeout = 1.milliseconds,60 ),61 )62 val executor = TestCaseExecutor(NoopTestCaseExecutionListener, NoopCoroutineDispatcherFactory, ProjectConfiguration())63 // needs to run on a separate thread, so we don't interrupt our own thread64 withContext(Dispatchers.IO) {65 executor.execute(tc, NoopTestScope(testCase, coroutineContext))66 }67 }68 }69}
createSpecExecutorDelegate.kt
Source:createSpecExecutorDelegate.kt
...5import io.kotest.core.spec.Spec6import io.kotest.core.test.TestCase7import io.kotest.core.test.TestResult8import io.kotest.engine.listener.TestEngineListener9import io.kotest.engine.test.TestCaseExecutor10import io.kotest.engine.test.scopes.DuplicateNameHandlingTestScope11import io.kotest.engine.test.scopes.InOrderTestScope12import io.kotest.engine.test.listener.TestCaseExecutionListenerToTestEngineListenerAdapter13import io.kotest.mpp.log14import kotlin.coroutines.coroutineContext15@ExperimentalKotest16internal actual fun createSpecExecutorDelegate(17 listener: TestEngineListener,18 defaultCoroutineDispatcherFactory: CoroutineDispatcherFactory,19 configuration: ProjectConfiguration,20): SpecExecutorDelegate =21 DefaultSpecExecutorDelegate(listener, defaultCoroutineDispatcherFactory, configuration)22/**23 * A [SpecExecutorDelegate] that executes tests sequentially, using the calling thread24 * as the execution context for timeouts.25 */26@ExperimentalKotest27internal class DefaultSpecExecutorDelegate(28 private val listener: TestEngineListener,29 private val coroutineDispatcherFactory: CoroutineDispatcherFactory,30 private val configuration: ProjectConfiguration31) : SpecExecutorDelegate {32 private val materializer = Materializer(configuration)33 override suspend fun execute(spec: Spec): Map<TestCase, TestResult> {34 log { "DefaultSpecExecutorDelegate: Executing spec $spec" }35 materializer.materialize(spec)36 .forEach { testCase ->37 log { "DefaultSpecExecutorDelegate: Executing testCase $testCase" }38 val context = DuplicateNameHandlingTestScope(39 configuration.duplicateTestNameMode,40 InOrderTestScope(41 testCase,42 coroutineContext,43 configuration.duplicateTestNameMode,44 listener,45 coroutineDispatcherFactory,46 configuration47 )48 )49 TestCaseExecutor(50 TestCaseExecutionListenerToTestEngineListenerAdapter(listener),51 coroutineDispatcherFactory,52 configuration53 ).execute(testCase, context)54 }55 return emptyMap()56 }57}
InOrderTestScope.kt
Source:InOrderTestScope.kt
...8import io.kotest.core.test.TestResult9import io.kotest.core.test.TestScope10import io.kotest.engine.listener.TestEngineListener11import io.kotest.engine.spec.Materializer12import io.kotest.engine.test.TestCaseExecutor13import io.kotest.engine.test.listener.TestCaseExecutionListenerToTestEngineListenerAdapter14import io.kotest.mpp.log15import kotlin.coroutines.CoroutineContext16/**17 * A [TestScope] that executes nested tests as soon as they are discovered.18 */19@ExperimentalKotest20class InOrderTestScope(21 override val testCase: TestCase,22 override val coroutineContext: CoroutineContext,23 private val mode: DuplicateTestNameMode,24 private val listener: TestEngineListener,25 private val coroutineDispatcherFactory: CoroutineDispatcherFactory,26 private val configuration: ProjectConfiguration,27) : TestScope {28 private var failed = false29 override suspend fun registerTestCase(nested: NestedTest) {30 log { "InOrderTestScope: Nested test case discovered $nested" }31 val nestedTestCase = Materializer(configuration).materialize(nested, testCase)32 if (failed && (testCase.config.failfast || configuration.projectWideFailFast)) {33 log { "InOrderTestScope: A previous nested test failed and failfast is enabled - will mark this as ignored" }34 listener.testIgnored(nestedTestCase, "Failfast enabled on parent test")35 } else {36 val result = runTest(nestedTestCase, coroutineContext)37 if (result.isErrorOrFailure) {38 failed = true39 }40 }41 }42 private suspend fun runTest(43 testCase: TestCase,44 coroutineContext: CoroutineContext,45 ): TestResult {46 return TestCaseExecutor(47 TestCaseExecutionListenerToTestEngineListenerAdapter(listener),48 coroutineDispatcherFactory,49 configuration,50 ).execute(51 testCase,52 createSingleInstanceTestScope(53 testCase,54 coroutineContext,55 mode,56 listener,57 coroutineDispatcherFactory,58 configuration,59 )60 )...
TestCaseExecutor
Using AI Code Generation
1val executor = TestCaseExecutor()2val result = executor.execute(testCase)3println(result)4val executor = TestCaseExecutor()5val result = executor.execute(testCase)6println(result)7val executor = TestCaseExecutor()8val result = executor.execute(testCase)9println(result)10val executor = TestCaseExecutor()11val result = executor.execute(testCase)12println(result)13val executor = TestCaseExecutor()14val result = executor.execute(testCase)15println(result)16val executor = TestCaseExecutor()17val result = executor.execute(testCase)18println(result)19val executor = TestCaseExecutor()20val result = executor.execute(testCase)21println(result)22val executor = TestCaseExecutor()23val result = executor.execute(testCase)24println(result)25val executor = TestCaseExecutor()26val result = executor.execute(testCase)27println(result)28val executor = TestCaseExecutor()29val result = executor.execute(testCase)30println(result)
TestCaseExecutor
Using AI Code Generation
1val result = executor.execute(testCase)2You can also use the TestCaseExecutor class of io.kotest.engine.test package to execute a test case. The TestCaseExecutor class is a wrapper for the execute() method of the io.kotest.engine.test package. The following code snippet shows how to use the TestCaseExecutor class:3The following code snippet shows the implementation of the execute() method of the io.kotest.engine.test package:4The following code snippet shows how to use the execute() method of the io.kotest.engine.test package:5val result = execute(testCase)6val result = execute(testCase)7The following code snippet shows the implementation of the execute() method of the io.kotest.engine.test package:8The following code snippet shows how to use the execute() method of the io.kotest.engine.test package:9val result = execute(testCase)10val result = execute(testCase)11The following code snippet shows the implementation of the execute() method of the io.kotest.engine.test package:12The following code snippet shows how to use the execute() method of the io.kotest.engine.test package:13val result = execute(testCase)14val result = execute(testCase)15The following code snippet shows the implementation of the execute() method of the io.kotest.engine.test package:16The following code snippet shows how to use the execute() method of the io.kotest.engine.test package:17val result = execute(testCase)18val result = execute(testCase)19The following code snippet shows the implementation of the execute() method of the
TestCaseExecutor
Using AI Code Generation
1val executor = TestCaseExecutor()2executor.execute(testCase)3executor.executeInScope(testCase) { result ->4}5val result = executor.executeAndCapture(testCase)6val result = executor.executeWithExceptionCapture(testCase)7executor.executeAndFireCallbacks(testCase, listener)8executor.executeInScopeAndFireCallbacks(testCase, listener) { result ->9}10val result = executor.executeAndFireCallbacksAndCapture(testCase, listener)11val result = executor.executeWithExceptionCaptureAndFireCallbacks(testCase, listener)
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!!