Best Kotest code snippet using io.kotest.runner.junit.platform.JUnitTestEngineListener
JUnitTestEngineListenerTest.kt
Source:JUnitTestEngineListenerTest.kt
...13import io.kotest.core.test.TestType14import io.kotest.engine.interceptors.EngineContext15import io.kotest.engine.listener.NoopTestEngineListener16import io.kotest.matchers.shouldBe17import io.kotest.runner.junit.platform.JUnitTestEngineListener18import org.junit.platform.engine.EngineExecutionListener19import org.junit.platform.engine.TestDescriptor20import org.junit.platform.engine.TestExecutionResult21import org.junit.platform.engine.UniqueId22import org.junit.platform.engine.reporting.ReportEntry23import org.junit.platform.engine.support.descriptor.EngineDescriptor24import kotlin.time.Duration.Companion.milliseconds25import kotlin.time.Duration.Companion.seconds26class JUnitTestEngineListenerTest : FunSpec({27 val root = EngineDescriptor(UniqueId.forEngine("kotest"), "kotest")28 val tc1 = TestCase(29 MySpec::class.toDescriptor().append("foo"),30 TestName("foo"),31 MySpec(),32 {},33 sourceRef(),34 TestType.Container,35 )36 val tc2 = TestCase(37 tc1.descriptor.append("bar"),38 TestName("bar"),39 tc1.spec,40 {},41 sourceRef(),42 TestType.Test,43 parent = tc1,44 )45 val tc3 = TestCase(46 MySpec2::class.toDescriptor().append("baz"),47 TestName("baz"),48 MySpec2(),49 {},50 sourceRef(),51 TestType.Container,52 )53 test("an error before spec started should show spec with a dummy error test") {54 val track = EventTrackingEngineExecutionListener()55 val listener = JUnitTestEngineListener(track, root)56 listener.specStarted(MySpec::class)57 listener.specFinished(MySpec::class, TestResult.Error(0.seconds, Exception("CRRAACK")))58 track.events shouldBe listOf(59 EventTrackingEngineExecutionListener.Event.TestRegistered(60 "com.sksamuel.kotest.runner.junit5.MySpec",61 TestDescriptor.Type.CONTAINER62 ),63 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),64 EventTrackingEngineExecutionListener.Event.TestRegistered(65 "Exception",66 TestDescriptor.Type.TEST67 ),68 EventTrackingEngineExecutionListener.Event.ExecutionStarted("Exception"),69 EventTrackingEngineExecutionListener.Event.ExecutionFinished(70 "Exception",71 TestExecutionResult.Status.FAILED72 ),73 EventTrackingEngineExecutionListener.Event.ExecutionFinished(74 "com.sksamuel.kotest.runner.junit5.MySpec",75 TestExecutionResult.Status.FAILED76 ),77 )78 }79 test("an ignored spec should be skipped") {80 val track = EventTrackingEngineExecutionListener()81 val listener = JUnitTestEngineListener(track, root)82 listener.specIgnored(MySpec::class, "disabled foo")83 track.events shouldBe listOf(84 EventTrackingEngineExecutionListener.Event.ExecutionSkipped(85 "com.sksamuel.kotest.runner.junit5.MySpec",86 "disabled foo"87 )88 )89 }90 test("a successful root test should be marked as started and finished") {91 val track = EventTrackingEngineExecutionListener()92 val listener = JUnitTestEngineListener(track, root)93 listener.specStarted(MySpec::class)94 listener.testStarted(tc1)95 listener.testFinished(tc1, TestResult.Success(12.milliseconds))96 listener.specFinished(MySpec::class, TestResult.Success(0.seconds))97 track.events shouldBe listOf(98 EventTrackingEngineExecutionListener.Event.TestRegistered("com.sksamuel.kotest.runner.junit5.MySpec", TestDescriptor.Type.CONTAINER),99 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),100 EventTrackingEngineExecutionListener.Event.TestRegistered("foo", TestDescriptor.Type.CONTAINER),101 EventTrackingEngineExecutionListener.Event.ExecutionStarted("foo"),102 EventTrackingEngineExecutionListener.Event.ExecutionFinished("foo", TestExecutionResult.Status.SUCCESSFUL),103 EventTrackingEngineExecutionListener.Event.ExecutionFinished("com.sksamuel.kotest.runner.junit5.MySpec", TestExecutionResult.Status.SUCCESSFUL),104 )105 }106 test("a failed root test should be marked as FAILED") {107 val track = EventTrackingEngineExecutionListener()108 val listener = JUnitTestEngineListener(track, root)109 listener.specStarted(MySpec::class)110 listener.testStarted(tc1)111 listener.testFinished(tc1, TestResult.Failure(5.milliseconds, AssertionError("whack!")))112 listener.specFinished(MySpec::class, TestResult.Success(0.seconds))113 track.events shouldBe listOf(114 EventTrackingEngineExecutionListener.Event.TestRegistered(115 "com.sksamuel.kotest.runner.junit5.MySpec",116 TestDescriptor.Type.CONTAINER117 ),118 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),119 EventTrackingEngineExecutionListener.Event.TestRegistered("foo", TestDescriptor.Type.CONTAINER),120 EventTrackingEngineExecutionListener.Event.ExecutionStarted("foo"),121 EventTrackingEngineExecutionListener.Event.ExecutionFinished("foo", TestExecutionResult.Status.FAILED),122 EventTrackingEngineExecutionListener.Event.ExecutionFinished(123 "com.sksamuel.kotest.runner.junit5.MySpec",124 TestExecutionResult.Status.SUCCESSFUL125 ),126 )127 }128 test("an ignored root test should be marked as skipped") {129 val track = EventTrackingEngineExecutionListener()130 val listener = JUnitTestEngineListener(track, root)131 listener.specStarted(MySpec::class)132 listener.testIgnored(tc1, "secret!")133 listener.specFinished(MySpec::class, TestResult.Success(0.seconds))134 track.events shouldBe listOf(135 EventTrackingEngineExecutionListener.Event.TestRegistered("com.sksamuel.kotest.runner.junit5.MySpec", TestDescriptor.Type.CONTAINER),136 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),137 EventTrackingEngineExecutionListener.Event.TestRegistered("foo", TestDescriptor.Type.TEST),138 EventTrackingEngineExecutionListener.Event.ExecutionSkipped("foo", "secret!"),139 EventTrackingEngineExecutionListener.Event.ExecutionFinished("com.sksamuel.kotest.runner.junit5.MySpec", TestExecutionResult.Status.SUCCESSFUL),140 )141 }142 test("a successful nested test should be marked as SUCCESSFUL with type TEST") {143 val track = EventTrackingEngineExecutionListener()144 val listener = JUnitTestEngineListener(track, root)145 listener.specStarted(MySpec::class)146 listener.testStarted(tc1)147 listener.testStarted(tc2)148 listener.testFinished(tc2, TestResult.Success(3.milliseconds))149 listener.testFinished(tc1, TestResult.Success(7.milliseconds))150 listener.specFinished(MySpec::class, TestResult.Success(0.seconds))151 track.events shouldBe listOf(152 EventTrackingEngineExecutionListener.Event.TestRegistered("com.sksamuel.kotest.runner.junit5.MySpec", TestDescriptor.Type.CONTAINER),153 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),154 EventTrackingEngineExecutionListener.Event.TestRegistered("foo", TestDescriptor.Type.CONTAINER),155 EventTrackingEngineExecutionListener.Event.ExecutionStarted("foo"),156 EventTrackingEngineExecutionListener.Event.TestRegistered("bar", TestDescriptor.Type.TEST),157 EventTrackingEngineExecutionListener.Event.ExecutionStarted("bar"),158 EventTrackingEngineExecutionListener.Event.ExecutionFinished("bar", TestExecutionResult.Status.SUCCESSFUL),159 EventTrackingEngineExecutionListener.Event.ExecutionFinished("foo", TestExecutionResult.Status.SUCCESSFUL),160 EventTrackingEngineExecutionListener.Event.ExecutionFinished("com.sksamuel.kotest.runner.junit5.MySpec", TestExecutionResult.Status.SUCCESSFUL),161 )162 }163 test("a failed nested test should be marked as FAILED with type TEST") {164 val track = EventTrackingEngineExecutionListener()165 val listener = JUnitTestEngineListener(track, root)166 listener.specStarted(MySpec::class)167 listener.testStarted(tc1)168 listener.testStarted(tc2)169 listener.testFinished(tc2, TestResult.Failure(5.milliseconds, AssertionError("whack!")))170 listener.testFinished(tc1, TestResult.Success(7.milliseconds))171 listener.specFinished(MySpec::class, TestResult.Success(0.seconds))172 track.events shouldBe listOf(173 EventTrackingEngineExecutionListener.Event.TestRegistered("com.sksamuel.kotest.runner.junit5.MySpec", TestDescriptor.Type.CONTAINER),174 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),175 EventTrackingEngineExecutionListener.Event.TestRegistered("foo", TestDescriptor.Type.CONTAINER),176 EventTrackingEngineExecutionListener.Event.ExecutionStarted("foo"),177 EventTrackingEngineExecutionListener.Event.TestRegistered("bar", TestDescriptor.Type.TEST),178 EventTrackingEngineExecutionListener.Event.ExecutionStarted("bar"),179 EventTrackingEngineExecutionListener.Event.ExecutionFinished("bar", TestExecutionResult.Status.FAILED),180 EventTrackingEngineExecutionListener.Event.ExecutionFinished("foo", TestExecutionResult.Status.SUCCESSFUL),181 EventTrackingEngineExecutionListener.Event.ExecutionFinished("com.sksamuel.kotest.runner.junit5.MySpec", TestExecutionResult.Status.SUCCESSFUL),182 )183 }184 test("an ignored nested test should be marked as skipped") {185 val track = EventTrackingEngineExecutionListener()186 val listener = JUnitTestEngineListener(track, root)187 listener.specStarted(MySpec::class)188 listener.testStarted(tc1)189 listener.testIgnored(tc2, "secret!")190 listener.testFinished(tc1, TestResult.Success(7.milliseconds))191 listener.specFinished(MySpec::class, TestResult.Success(0.seconds))192 track.events shouldBe listOf(193 EventTrackingEngineExecutionListener.Event.TestRegistered("com.sksamuel.kotest.runner.junit5.MySpec", TestDescriptor.Type.CONTAINER),194 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),195 EventTrackingEngineExecutionListener.Event.TestRegistered("foo", TestDescriptor.Type.CONTAINER),196 EventTrackingEngineExecutionListener.Event.ExecutionStarted("foo"),197 EventTrackingEngineExecutionListener.Event.TestRegistered("bar", TestDescriptor.Type.TEST),198 EventTrackingEngineExecutionListener.Event.ExecutionSkipped("bar", "secret!"),199 EventTrackingEngineExecutionListener.Event.ExecutionFinished("foo", TestExecutionResult.Status.SUCCESSFUL),200 EventTrackingEngineExecutionListener.Event.ExecutionFinished("com.sksamuel.kotest.runner.junit5.MySpec", TestExecutionResult.Status.SUCCESSFUL),201 )202 }203 test("an error in the spec should add a placeholder test with the error along with completed tests") {204 val track = EventTrackingEngineExecutionListener()205 val listener = JUnitTestEngineListener(track, root)206 listener.specStarted(MySpec::class)207 listener.testStarted(tc1)208 listener.testFinished(tc1, TestResult.Success(7.milliseconds))209 listener.specFinished(MySpec::class, TestResult.Error(0.seconds, Exception("THWAPP!")))210 track.events shouldBe listOf(211 EventTrackingEngineExecutionListener.Event.TestRegistered(212 "com.sksamuel.kotest.runner.junit5.MySpec",213 TestDescriptor.Type.CONTAINER214 ),215 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),216 EventTrackingEngineExecutionListener.Event.TestRegistered("foo", TestDescriptor.Type.CONTAINER),217 EventTrackingEngineExecutionListener.Event.ExecutionStarted("foo"),218 EventTrackingEngineExecutionListener.Event.ExecutionFinished("foo", TestExecutionResult.Status.SUCCESSFUL),219 EventTrackingEngineExecutionListener.Event.TestRegistered("Exception", TestDescriptor.Type.TEST),220 EventTrackingEngineExecutionListener.Event.ExecutionStarted("Exception"),221 EventTrackingEngineExecutionListener.Event.ExecutionFinished("Exception", TestExecutionResult.Status.FAILED),222 EventTrackingEngineExecutionListener.Event.ExecutionFinished(223 "com.sksamuel.kotest.runner.junit5.MySpec",224 TestExecutionResult.Status.FAILED225 ),226 )227 }228 test("state should be reset after spec") {229 val track = EventTrackingEngineExecutionListener()230 val listener = JUnitTestEngineListener(track, root)231 listener.specStarted(MySpec::class)232 listener.testStarted(tc1)233 listener.testFinished(tc1, TestResult.Success(7.milliseconds))234 listener.specFinished(MySpec::class, TestResult.Success(0.seconds))235 listener.specStarted(MySpec2::class)236 listener.testStarted(tc3)237 listener.testFinished(tc3, TestResult.Success(4.milliseconds))238 listener.specFinished(MySpec2::class, TestResult.Success(0.seconds))239 track.events shouldBe listOf(240 EventTrackingEngineExecutionListener.Event.TestRegistered(241 "com.sksamuel.kotest.runner.junit5.MySpec",242 TestDescriptor.Type.CONTAINER243 ),244 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),245 EventTrackingEngineExecutionListener.Event.TestRegistered("foo", TestDescriptor.Type.CONTAINER),246 EventTrackingEngineExecutionListener.Event.ExecutionStarted("foo"),247 EventTrackingEngineExecutionListener.Event.ExecutionFinished("foo", TestExecutionResult.Status.SUCCESSFUL),248 EventTrackingEngineExecutionListener.Event.ExecutionFinished(249 "com.sksamuel.kotest.runner.junit5.MySpec",250 TestExecutionResult.Status.SUCCESSFUL251 ),252 EventTrackingEngineExecutionListener.Event.TestRegistered(253 "com.sksamuel.kotest.runner.junit5.MySpec2",254 TestDescriptor.Type.CONTAINER255 ),256 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec2"),257 EventTrackingEngineExecutionListener.Event.TestRegistered("baz", TestDescriptor.Type.CONTAINER),258 EventTrackingEngineExecutionListener.Event.ExecutionStarted("baz"),259 EventTrackingEngineExecutionListener.Event.ExecutionFinished("baz", TestExecutionResult.Status.SUCCESSFUL),260 EventTrackingEngineExecutionListener.Event.ExecutionFinished(261 "com.sksamuel.kotest.runner.junit5.MySpec2",262 TestExecutionResult.Status.SUCCESSFUL263 ),264 )265 }266 test("state should be reset after ignored spec") {267 val track = EventTrackingEngineExecutionListener()268 val listener = JUnitTestEngineListener(track, root)269 listener.specIgnored(MySpec::class, null)270 listener.specStarted(MySpec2::class)271 listener.testStarted(tc3)272 listener.testFinished(tc3, TestResult.Success(4.milliseconds))273 listener.specFinished(MySpec2::class, TestResult.Success(0.seconds))274 track.events shouldBe listOf(275 EventTrackingEngineExecutionListener.Event.ExecutionSkipped("com.sksamuel.kotest.runner.junit5.MySpec", null),276 EventTrackingEngineExecutionListener.Event.TestRegistered(277 "com.sksamuel.kotest.runner.junit5.MySpec2",278 TestDescriptor.Type.CONTAINER279 ),280 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec2"),281 EventTrackingEngineExecutionListener.Event.TestRegistered("baz", TestDescriptor.Type.CONTAINER),282 EventTrackingEngineExecutionListener.Event.ExecutionStarted("baz"),283 EventTrackingEngineExecutionListener.Event.ExecutionFinished("baz", TestExecutionResult.Status.SUCCESSFUL),284 EventTrackingEngineExecutionListener.Event.ExecutionFinished(285 "com.sksamuel.kotest.runner.junit5.MySpec2",286 TestExecutionResult.Status.SUCCESSFUL287 ),288 )289 }290 test("listener should support full test paths") {291 val track = EventTrackingEngineExecutionListener()292 val conf = ProjectConfiguration()293 conf.displayFullTestPath = true294 val listener = JUnitTestEngineListener(track, root)295 listener.engineInitialized(EngineContext(TestSuite.empty, NoopTestEngineListener, TagExpression.Empty, conf))296 listener.specStarted(MySpec::class)297 listener.testStarted(tc1)298 listener.testStarted(tc2)299 listener.testFinished(tc2, TestResult.Success(3.milliseconds))300 listener.testFinished(tc1, TestResult.Success(7.milliseconds))301 listener.specFinished(MySpec::class, TestResult.Success(0.seconds))302 track.events shouldBe listOf(303 EventTrackingEngineExecutionListener.Event.TestRegistered("com.sksamuel.kotest.runner.junit5.MySpec", TestDescriptor.Type.CONTAINER),304 EventTrackingEngineExecutionListener.Event.ExecutionStarted("com.sksamuel.kotest.runner.junit5.MySpec"),305 EventTrackingEngineExecutionListener.Event.TestRegistered("foo", TestDescriptor.Type.CONTAINER),306 EventTrackingEngineExecutionListener.Event.ExecutionStarted("foo"),307 EventTrackingEngineExecutionListener.Event.TestRegistered("foo bar", TestDescriptor.Type.TEST),308 EventTrackingEngineExecutionListener.Event.ExecutionStarted("foo bar"),...
JUnitTestEngineListener.kt
Source:JUnitTestEngineListener.kt
...69 * Call addChild _before_ registering test otherwise will appear in the display out of order.70 * Must start tests after their parent or they can go missing.71 * Sibling containers can start and finish in parallel.72 */73class JUnitTestEngineListener(74 private val listener: EngineExecutionListener,75 val root: EngineDescriptor,76) : AbstractTestEngineListener() {77 private val logger = Logger(JUnitTestEngineListener::class)78 private var formatter: DisplayNameFormatter = DefaultDisplayNameFormatter(ProjectConfiguration())79 // contains a mapping of junit TestDescriptor's, so we can find previously registered tests80 private val descriptors = mutableMapOf<Descriptor, TestDescriptor>()81 private var started = false82 private val startedTests = mutableSetOf<Descriptor.TestDescriptor>()83 // the root tests are our entry point when outputting results84 private val rootTests = mutableListOf<TestCase>()85 private var failOnIgnoredTests = false86 private val children = mutableMapOf<Descriptor, MutableList<TestCase>>()87 private val results = mutableMapOf<Descriptor, TestResult>()88 private val dummies = hashSetOf<String>()89 override suspend fun engineStarted() {90 logger.log { Pair(null, "Engine started") }91 listener.executionStarted(root)...
KotestJunitPlatformTestEngine.kt
Source:KotestJunitPlatformTestEngine.kt
...47 private fun execute(request: ExecutionRequest, root: KotestEngineDescriptor) {48 val configuration = ProjectConfiguration()49 val listener = ThreadSafeTestEngineListener(50 PinnedSpecTestEngineListener(51 JUnitTestEngineListener(52 SynchronizedEngineExecutionListener(53 request.engineExecutionListener54 ),55 root,56 )57 )58 )59 request.configurationParameters.get("kotest.extensions").orElseGet { "" }60 .split(',')61 .map { it.trim() }62 .filter { it.isNotBlank() }63 .map { Class.forName(it).newInstance() as Extension }64 .forEach { configuration.registry.add(it) }65 TestEngineLauncher(listener)...
SpecInitializationErrorTest.kt
Source:SpecInitializationErrorTest.kt
...6import io.kotest.engine.concurrency.NoopCoroutineDispatcherFactory7import io.kotest.engine.interceptors.EngineContext8import io.kotest.engine.spec.SpecExecutor9import io.kotest.matchers.shouldBe10import io.kotest.runner.junit.platform.JUnitTestEngineListener11import io.kotest.runner.junit.platform.KotestEngineDescriptor12import org.junit.platform.engine.EngineExecutionListener13import org.junit.platform.engine.TestDescriptor14import org.junit.platform.engine.TestExecutionResult15import org.junit.platform.engine.UniqueId16import org.junit.platform.engine.reporting.ReportEntry17@ExperimentalKotest18class SpecInitializationErrorTest : FunSpec({19 test("an error in a class field should fail spec") {20 val root = KotestEngineDescriptor(21 UniqueId.forEngine("kotest"),22 emptyList(),23 emptyList(),24 emptyList(),25 null,26 )27 val finished = mutableMapOf<String, TestExecutionResult.Status>()28 val engineListener = object : EngineExecutionListener {29 override fun executionFinished(testDescriptor: TestDescriptor, testExecutionResult: TestExecutionResult) {30 finished[testDescriptor.displayName] = testExecutionResult.status31 }32 override fun reportingEntryPublished(testDescriptor: TestDescriptor?, entry: ReportEntry?) {}33 override fun executionSkipped(testDescriptor: TestDescriptor?, reason: String?) {}34 override fun executionStarted(testDescriptor: TestDescriptor?) {}35 override fun dynamicTestRegistered(testDescriptor: TestDescriptor?) {}36 }37 val listener = JUnitTestEngineListener(engineListener, root)38 val executor = SpecExecutor(NoopCoroutineDispatcherFactory, EngineContext(ProjectConfiguration()).mergeListener(listener))39 executor.execute(SpecRef.Reference(SpecWithFieldError::class))40 finished.toMap() shouldBe mapOf(41 "SpecInstantiationException" to TestExecutionResult.Status.FAILED,42 "com.sksamuel.kotest.runner.junit5.SpecWithFieldError" to TestExecutionResult.Status.FAILED43 )44 }45 test("an error in a class initializer should fail spec") {46 val root = KotestEngineDescriptor(47 UniqueId.forEngine("kotest"),48 emptyList(),49 emptyList(),50 emptyList(),51 null,52 )53 val finished = mutableMapOf<String, TestExecutionResult.Status>()54 val engineListener = object : EngineExecutionListener {55 override fun executionFinished(testDescriptor: TestDescriptor, testExecutionResult: TestExecutionResult) {56 finished[testDescriptor.displayName] = testExecutionResult.status57 }58 override fun reportingEntryPublished(testDescriptor: TestDescriptor?, entry: ReportEntry?) {}59 override fun executionSkipped(testDescriptor: TestDescriptor?, reason: String?) {}60 override fun executionStarted(testDescriptor: TestDescriptor?) {}61 override fun dynamicTestRegistered(testDescriptor: TestDescriptor?) {}62 }63 val listener = JUnitTestEngineListener(engineListener, root)64 val executor = SpecExecutor(NoopCoroutineDispatcherFactory, EngineContext(ProjectConfiguration()).mergeListener(listener))65 executor.execute(SpecRef.Reference(SpecWithInitError::class))66 finished.toMap() shouldBe mapOf(67 "SpecInstantiationException" to TestExecutionResult.Status.FAILED,68 "com.sksamuel.kotest.runner.junit5.SpecWithInitError" to TestExecutionResult.Status.FAILED,69 )70 }71})72private class SpecWithFieldError : FunSpec() {73 private val err = "failme".apply { error("foo") }74 init {75 test("foo") {76 }77 }...
JUnitTestRunnerListenerTest.kt
Source:JUnitTestRunnerListenerTest.kt
...8import io.kotest.core.test.TestResult9import io.kotest.core.test.TestType10import io.kotest.engine.test.createTestResult11import io.kotest.matchers.shouldBe12import io.kotest.runner.junit.platform.JUnitTestEngineListener13import io.kotest.runner.junit.platform.KotestEngineDescriptor14import org.junit.platform.engine.EngineExecutionListener15import org.junit.platform.engine.TestDescriptor16import org.junit.platform.engine.TestExecutionResult17import 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.SUCCESSFUL...
JUnitTestEngineListener
Using AI Code Generation
1val listener = JUnitTestEngineListener()2val listener = JUnit4TestEngineListener()3val listener = JUnit5TestEngineListener()4val listener = TestNGTestEngineListener()5val listener = SpekTestEngineListener()6val listener = SpockTestEngineListener()7val listener = JUnitPlatformTestEngineListener()8val listener = JUnit4TestEngineListener()9val listener = JUnit5TestEngineListener()10val listener = TestNGTestEngineListener()11val listener = SpekTestEngineListener()12val listener = SpockTestEngineListener()13val listener = JUnitPlatformTestEngineListener()14val listener = JUnit4TestEngineListener()15val listener = JUnit5TestEngineListener()16val listener = TestNGTestEngineListener()17val listener = SpekTestEngineListener()
JUnitTestEngineListener
Using AI Code Generation
1val testEngineListener = JUnitTestEngineListener()2val testCaseListener = JUnitTestCaseListener()3val testEngineListener = JUnitTestEngineListener()4val testCaseListener = JUnitTestCaseListener()5val testEngineListener = JUnitTestEngineListener()6val testCaseListener = JUnitTestCaseListener()7val testEngineListener = JUnitTestEngineListener()8val testCaseListener = JUnitTestCaseListener()9val testEngineListener = JUnitTestEngineListener()10val testCaseListener = JUnitTestCaseListener()11val testEngineListener = JUnitTestEngineListener()12val testCaseListener = JUnitTestCaseListener()13val testEngineListener = JUnitTestEngineListener()14val testCaseListener = JUnitTestCaseListener()15val testEngineListener = JUnitTestEngineListener()16val testCaseListener = JUnitTestCaseListener()17val testEngineListener = JUnitTestEngineListener()
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!!