How to use CollectingTestEngineListener class of io.kotest.engine.listener package

Best Kotest code snippet using io.kotest.engine.listener.CollectingTestEngineListener

ExtensionErrorsTest.kt

Source:ExtensionErrorsTest.kt Github

copy

Full Screen

...5import io.kotest.core.test.TestResult6import io.kotest.engine.TestEngineLauncher7import io.kotest.engine.extensions.ExtensionException8import io.kotest.engine.extensions.MultipleExceptions9import io.kotest.engine.listener.CollectingTestEngineListener10import io.kotest.inspectors.forAll11import io.kotest.matchers.collections.shouldHaveSize12import io.kotest.matchers.types.shouldBeInstanceOf13class ExtensionErrorsTest : FunSpec() {14 init {15 test("beforeSpec function overrides should be wrapped") {16 val collector = CollectingTestEngineListener()17 TestEngineLauncher(collector)18 .withClasses(BeforeSpecFunctionOverrideError::class)19 .launch()20 val error = collector.specs.values.first().errorOrNull21 error.shouldBeInstanceOf<ExtensionException.BeforeSpecException>()22 }23 test("beforeSpec DSL errors should be wrapped") {24 val collector = CollectingTestEngineListener()25 TestEngineLauncher(collector)26 .withClasses(BeforeSpecDSLError::class)27 .launch()28 val error = collector.specs.values.first().errorOrNull29 error.shouldBeInstanceOf<ExtensionException.BeforeSpecException>()30 }31 test("multiple beforeSpec should be collected") {32 val collector = CollectingTestEngineListener()33 TestEngineLauncher(collector)34 .withClasses(MultipleBeforeSpecErrors::class)35 .launch()36 val error = collector.specs.values.first().errorOrNull37 error.shouldBeInstanceOf<MultipleExceptions>()38 error.causes.shouldHaveSize(3)39 error.causes.forAll { it.shouldBeInstanceOf<ExtensionException.BeforeSpecException>() }40 }41 test("afterSpec function overrides should be wrapped") {42 val collector = CollectingTestEngineListener()43 TestEngineLauncher(collector)44 .withClasses(AfterSpecFunctionOverrideError::class)45 .launch()46 val error = collector.specs.values.first().errorOrNull47 error.shouldBeInstanceOf<ExtensionException.AfterSpecException>()48 }49 test("afterSpec DSL errors should be wrapped") {50 val collector = CollectingTestEngineListener()51 TestEngineLauncher(collector)52 .withClasses(AfterSpecDSLError::class)53 .launch()54 val error = collector.specs.values.first().errorOrNull55 error.shouldBeInstanceOf<ExtensionException.AfterSpecException>()56 }57 test("multiple afterSpec should be collected") {58 val collector = CollectingTestEngineListener()59 TestEngineLauncher(collector)60 .withClasses(MultipleAfterSpecErrors::class)61 .launch()62 val error = collector.specs.values.first().errorOrNull63 error.shouldBeInstanceOf<MultipleExceptions>()64 error.causes.shouldHaveSize(3)65 error.causes.forAll { it.shouldBeInstanceOf<ExtensionException.AfterSpecException>() }66 }67 test("beforeTest function overrides should be wrapped") {68 val collector = CollectingTestEngineListener()69 TestEngineLauncher(collector)70 .withClasses(BeforeTestFunctionOverrideError::class)71 .launch()72 val error = collector.tests.values.first().errorOrNull73 error.shouldBeInstanceOf<ExtensionException.BeforeTestException>()74 }75 test("beforeTest DSL errors should be wrapped") {76 val collector = CollectingTestEngineListener()77 TestEngineLauncher(collector)78 .withClasses(BeforeTestDSLError::class)79 .launch()80 val error = collector.tests.values.first().errorOrNull81 error.shouldBeInstanceOf<ExtensionException.BeforeTestException>()82 }83 test("multiple beforeTest errors should be collected") {84 val collector = CollectingTestEngineListener()85 TestEngineLauncher(collector)86 .withClasses(MultipleBeforeTestErrors::class)87 .launch()88 val error = collector.tests.values.first().errorOrNull89 error.shouldBeInstanceOf<MultipleExceptions>()90 error.causes.shouldHaveSize(3)91 error.causes.forAll { it.shouldBeInstanceOf<ExtensionException.BeforeTestException>() }92 }93 test("afterTest function overrides should be wrapped") {94 val collector = CollectingTestEngineListener()95 TestEngineLauncher(collector)96 .withClasses(AfterTestFunctionOverrideError::class)97 .launch()98 val error = collector.tests.values.first().errorOrNull99 error.shouldBeInstanceOf<ExtensionException.AfterTestException>()100 }101 test("afterTest DSL errors should be wrapped") {102 val collector = CollectingTestEngineListener()103 TestEngineLauncher(collector)104 .withClasses(AfterTestDSLError::class)105 .launch()106 val error = collector.tests.values.first().errorOrNull107 error.shouldBeInstanceOf<ExtensionException.AfterTestException>()108 }109 test("multiple afterTest errors should be collected") {110 val collector = CollectingTestEngineListener()111 TestEngineLauncher(collector)112 .withClasses(MultipleAfterTestErrors::class)113 .launch()114 val error = collector.tests.values.first().errorOrNull115 error.shouldBeInstanceOf<MultipleExceptions>()116 error.causes.shouldHaveSize(3)117 error.causes.forAll { it.shouldBeInstanceOf<ExtensionException.AfterTestException>() }118 }119 }120}121private class BeforeSpecFunctionOverrideError : FunSpec() {122 override suspend fun beforeSpec(spec: Spec) {123 error("foo")124 }...

Full Screen

Full Screen

IgnoredTestReasonTest.kt

Source:IgnoredTestReasonTest.kt Github

copy

Full Screen

...6import 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}...

Full Screen

Full Screen

AfterSpecListenerTest.kt

Source:AfterSpecListenerTest.kt Github

copy

Full Screen

...7import io.kotest.core.spec.Spec8import io.kotest.core.spec.style.FunSpec9import io.kotest.engine.TestEngineLauncher10import io.kotest.engine.extensions.ExtensionException11import io.kotest.engine.listener.CollectingTestEngineListener12import io.kotest.engine.listener.NoopTestEngineListener13import io.kotest.matchers.booleans.shouldBeTrue14import io.kotest.matchers.shouldBe15import io.kotest.matchers.types.shouldBeInstanceOf16import java.util.concurrent.atomic.AtomicInteger17@Isolate18class AfterSpecListenerTest : FunSpec() {19 init {20 test("AfterSpecListener's should be triggered for a spec with tests") {21 counter.set(0)22 val c = ProjectConfiguration()23 c.registry.add(MyAfterSpecListener)24 val collector = CollectingTestEngineListener()25 TestEngineLauncher(collector)26 .withClasses(MyPopulatedSpec2::class)27 .withConfiguration(c)28 .launch()29 collector.specs.size shouldBe 130 collector.tests.size shouldBe 131 counter.get() shouldBe 532 }33 test("AfterSpecListener's exceptions should be propagated to specExit") {34 val collector = CollectingTestEngineListener()35 TestEngineLauncher(collector)36 .withClasses(MyErrorSpec2::class)37 .launch()38 collector.specs.size shouldBe 139 collector.specs[MyErrorSpec2::class]!!.errorOrNull.shouldBeInstanceOf<ExtensionException.AfterSpecException>()40 collector.tests.size shouldBe 141 }42 test("AfterSpecListener's should NOT be triggered for a spec without tests") {43 val c = ProjectConfiguration()44 c.registry.add(MyAfterSpecListener)45 counter.set(0)46 TestEngineLauncher(NoopTestEngineListener)47 .withClasses(MyEmptySpec2::class)48 .withConfiguration(c)49 .launch()50 counter.get() shouldBe 051 }52 test("inline afterSpec functions should be invoked") {53 TestEngineLauncher(NoopTestEngineListener)54 .withClasses(InlineAfterSpec::class)55 .launch()56 inlineAfterSpec.shouldBeTrue()57 }58 test("f:inline afterSpec function errors should be caught") {59 val collector = CollectingTestEngineListener()60 TestEngineLauncher(collector)61 .withClasses(InlineAfterSpecError::class)62 .launch()63 collector.specs.size.shouldBe(1)64 collector.specs[InlineAfterSpecError::class]!!.errorOrNull.shouldBeInstanceOf<ExtensionException.AfterSpecException>()65 }66 }67}68private val counter = AtomicInteger(0)69private object MyAfterSpecListener : AfterSpecListener {70 override val name: String = "MyAfterSpecListener"71 override suspend fun afterSpec(spec: Spec) {72 counter.incrementAndGet()73 }...

Full Screen

Full Screen

ActionTest.kt

Source:ActionTest.kt Github

copy

Full Screen

...12import 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 }...

Full Screen

Full Screen

LateRootTestDefinitionTest.kt

Source:LateRootTestDefinitionTest.kt Github

copy

Full Screen

...8import 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}...

Full Screen

Full Screen

AnnotationSpecTest.kt

Source:AnnotationSpecTest.kt Github

copy

Full Screen

2import io.kotest.core.descriptors.DescriptorId3import io.kotest.core.spec.style.AnnotationSpec4import io.kotest.core.spec.style.DescribeSpec5import io.kotest.engine.TestEngineLauncher6import io.kotest.engine.listener.CollectingTestEngineListener7import io.kotest.matchers.maps.shouldHaveSize8import io.kotest.matchers.shouldBe9class AnnotationSpecTest : DescribeSpec({10 describe("An AnnotationSpec") {11 it("should detect public and private methods annotated with @Test") {12 val listener = CollectingTestEngineListener()13 TestEngineLauncher(listener).withClasses(AnnotationSpecClass::class).launch()14 listener.tests.shouldHaveSize(2)15 }16// it("should detect nested classes") {17// val listener = CollectingTestEngineListener()18// TestEngineLauncher(listener).withClasses(AnnotationSpecWithNested::class).launch()19// listener.tests.shouldHaveSize(2)20// }21 it("should support throwing exceptions with @Test(expected=foo)") {22 val listener = CollectingTestEngineListener()23 TestEngineLauncher(listener).withClasses(AnnotationSpecWithExceptions::class).launch()24 val ds = listener.tests.mapKeys { it.key.descriptor.id }25 ds[DescriptorId("test1")]?.isSuccess shouldBe true26 }27 it("should fail on unexpected exception") {28 val listener = CollectingTestEngineListener()29 TestEngineLauncher(listener).withClasses(AnnotationSpecWithExceptions::class).launch()30 val ds = listener.tests.mapKeys { it.key.descriptor.id }31 ds[DescriptorId("test2")]?.isFailure shouldBe true32 }33 it("should fail on expected exception that wasn't thrown") {34 val listener = CollectingTestEngineListener()35 TestEngineLauncher(listener).withClasses(AnnotationSpecWithExceptions::class).launch()36 val ds = listener.tests.mapKeys { it.key.descriptor.id }37 ds[DescriptorId("test3")]?.isFailure shouldBe true38 }39 }40})41private class AnnotationSpecClass : AnnotationSpec() {42 @Test43 fun myTest() {44 }45 @Test46 private fun test2() {47 }48}...

Full Screen

Full Screen

SystemPropertyTimeoutTest.kt

Source:SystemPropertyTimeoutTest.kt Github

copy

Full Screen

1package io.kotest.engine.timeout2import io.kotest.core.internal.KotestEngineProperties3import io.kotest.core.spec.style.FunSpec4import io.kotest.engine.TestEngineLauncher5import io.kotest.engine.listener.CollectingTestEngineListener6import io.kotest.extensions.system.withSystemProperty7import io.kotest.matchers.shouldBe8import kotlinx.coroutines.delay9class SystemPropertyTimeoutTest : FunSpec() {10 init {11 test("system properties can be used for test timeouts") {12 withSystemProperty(KotestEngineProperties.timeout, "500") {13 val collector = CollectingTestEngineListener()14 TestEngineLauncher(collector)15 .withClasses(TimeoutTest::class)16 .launch()17 collector.tests.mapKeys { it.key.name.testName }["a"]?.isError shouldBe true18 }19 }20 test("system properties can be used for invocation timeouts") {21 withSystemProperty(KotestEngineProperties.invocationTimeout, "10") {22 val collector = CollectingTestEngineListener()23 TestEngineLauncher(collector)24 .withClasses(TimeoutTest::class)25 .launch()26 collector.tests.mapKeys { it.key.name.testName }["a"]?.isError shouldBe true27 }28 }29 }30}31private class TimeoutTest : FunSpec() {32 init {33 test("a").config(invocations = 1000000) {34 delay(100)35 }36 }...

Full Screen

Full Screen

main.kt

Source:main.kt Github

copy

Full Screen

...4import io.kotest.engine.listener.*5import kotlin.system.exitProcess6fun main(args: Array<String>) {7 val launcherArgs = parseLauncherArgs(args.toList())8 val collector = CollectingTestEngineListener()9 val listener = CompositeTestEngineListener(10 listOf(11 collector,12 LoggingTestEngineListener,13 ThreadSafeTestEngineListener( PinnedSpecTestEngineListener(EnhancedConsoleTestEngineListener(TermColors())) ),14 )15 )16 runBlocking {17 setupLauncher(launcherArgs, listener).fold(18 { it.async() },19 {20 // if we couldn't create the launcher we'll display those errors21 listener.engineStarted()22 listener.engineFinished(listOf(it))...

Full Screen

Full Screen

CollectingTestEngineListener

Using AI Code Generation

copy

Full Screen

1@RunWith(KotestEngineRunner::class)2@KotestEngineListener(CollectingTestEngineListener::class)3{4 fun test() {5 }6}

Full Screen

Full Screen

CollectingTestEngineListener

Using AI Code Generation

copy

Full Screen

1val listener = CollectingTestEngineListener()2val engine = KotestEngine(listener, emptyList())3engine.execute(listOf(MySpec::class))4listener.tests.forEach { result ->5println("Test name: ${result.testCase.description.name}")6println("Test status: ${result.status}")7println("Test duration: ${result.duration}")8}

Full Screen

Full Screen

CollectingTestEngineListener

Using AI Code Generation

copy

Full Screen

1val listener = CollectingTestEngineListener()2val engine = KotestEngineLauncher()3.engineListener(listener)4.suiteClasses(TestClass::class)5.launch()6testCount() - number of tests executed7successCount() - number of tests that succeeded8failureCount() - number of tests that failed9ignoredCount() - number of tests that were ignored10errorCount() - number of tests that threw an error11skippedCount() - number of tests that were skipped12testCount() - number of tests executed13successCount() - number of tests that succeeded14failureCount() - number of tests that failed15ignoredCount() - number of tests that were ignored16errorCount() - number of tests that threw an error17skippedCount() - number of tests that were skipped18testCount() - number of tests executed19successCount() - number of tests that succeeded20failureCount() - number of tests that failed21ignoredCount() - number of tests that were ignored22errorCount() - number of tests that threw an error23skippedCount() - number of tests that were skipped24testCount() - number of tests executed25successCount() - number of tests that succeeded26failureCount() - number of tests that failed27ignoredCount() - number of tests that were ignored28errorCount() - number of tests that threw an error29skippedCount() - number of tests that were skipped30name() - the name of the test31status() - the status of

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.

Most used methods in CollectingTestEngineListener

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful