Best Kotest code snippet using com.sksamuel.kotest.runner.junit5.JUnitTestRunnerListenerTest
JUnitTestRunnerListenerTest.kt
Source:JUnitTestRunnerListenerTest.kt
...17import org.junit.platform.engine.UniqueId18import org.junit.platform.engine.reporting.ReportEntry19import kotlin.time.Duration.Companion.milliseconds20import kotlin.time.Duration.Companion.seconds21class JUnitTestRunnerListenerTest : DescribeSpec({22 describe("as per the JUnit spec") {23 it("a failing test should not fail the parent test or parent spec") {24 val root = KotestEngineDescriptor(25 UniqueId.forEngine("kotest"),26 emptyList(),27 emptyList(),28 emptyList(),29 null,30 )31 val finished = mutableMapOf<String, TestExecutionResult.Status>()32 val engineListener = object : EngineExecutionListener {33 override fun executionFinished(testDescriptor: TestDescriptor, testExecutionResult: TestExecutionResult) {34 finished[testDescriptor.displayName] = testExecutionResult.status35 }36 override fun reportingEntryPublished(testDescriptor: TestDescriptor?, entry: ReportEntry?) {}37 override fun executionSkipped(testDescriptor: TestDescriptor?, reason: String?) {}38 override fun executionStarted(testDescriptor: TestDescriptor?) {}39 override fun dynamicTestRegistered(testDescriptor: TestDescriptor?) {}40 }41 val test1 = TestCase(42 JUnitTestRunnerListenerTest::class.toDescriptor().append("test1"),43 TestName("test1"),44 JUnitTestRunnerListenerTest(),45 { },46 sourceRef(),47 TestType.Container,48 parent = null,49 )50 val test2 = TestCase(51 test1.descriptor.append("test2"),52 TestName("test2"),53 JUnitTestRunnerListenerTest(),54 { },55 sourceRef(),56 TestType.Test,57 parent = test1,58 )59 val listener = JUnitTestEngineListener(engineListener, root)60 listener.engineStarted()61 listener.specStarted(JUnitTestRunnerListenerTest::class)62 listener.specStarted(JUnitTestRunnerListenerTest::class)63 listener.testStarted(test1)64 listener.testStarted(test2)65 listener.testFinished(test2, createTestResult(0.milliseconds, AssertionError("boom")))66 listener.testFinished(test1, TestResult.Success(0.milliseconds))67 listener.specFinished(JUnitTestRunnerListenerTest::class, TestResult.Success(0.seconds))68 listener.engineFinished(emptyList())69 finished.toMap() shouldBe mapOf(70 "test2" to TestExecutionResult.Status.FAILED,71 "test1" to TestExecutionResult.Status.SUCCESSFUL,72 "com.sksamuel.kotest.runner.junit5.JUnitTestRunnerListenerTest" to TestExecutionResult.Status.SUCCESSFUL,73 "Kotest" to TestExecutionResult.Status.SUCCESSFUL74 )75 }76 }77})...
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!!