How to use uniqueids class of io.kotest.runner.junit.platform package

Best Kotest code snippet using io.kotest.runner.junit.platform.uniqueids

DiscoveryTest.kt

Source:DiscoveryTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.runner.junit52import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.annotation.Isolate4import io.kotest.core.spec.style.FunSpec5import io.kotest.framework.discovery.Discovery6import io.kotest.framework.discovery.DiscoveryFilter7import io.kotest.framework.discovery.DiscoveryRequest8import io.kotest.framework.discovery.DiscoverySelector9import io.kotest.framework.discovery.Modifier10import io.kotest.matchers.shouldBe11import io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine12import org.junit.platform.engine.UniqueId13import org.junit.platform.engine.discovery.ClassNameFilter14import org.junit.platform.engine.discovery.DiscoverySelectors15import org.junit.platform.engine.discovery.PackageNameFilter16import org.junit.platform.launcher.EngineFilter.excludeEngines17import org.junit.platform.launcher.EngineFilter.includeEngines18import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder19@Isolate20class DiscoveryTest : FunSpec({21 test("kotest should return Nil if request excludes kotest engine") {22 val req = LauncherDiscoveryRequestBuilder.request()23 .filters(24 excludeEngines(KotestJunitPlatformTestEngine.EngineId)25 )26 .build()27 val engine = KotestJunitPlatformTestEngine()28 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))29 descriptor.classes.size shouldBe 030 }31 test("kotest should return Nil for uniqueId selectors") {32 val req = LauncherDiscoveryRequestBuilder.request().selectors(DiscoverySelectors.selectUniqueId("[engine:failgood]/[class:whatever]"))33 .filters(34 includeEngines(KotestJunitPlatformTestEngine.EngineId)35 )36 .build()37 val engine = KotestJunitPlatformTestEngine()38 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))39 descriptor.classes.size shouldBe 040 }41 test("kotest should throw for uniqueIds with kotest engine descriptor") {42 val req = LauncherDiscoveryRequestBuilder.request().selectors(DiscoverySelectors.selectUniqueId("[engine:${KotestJunitPlatformTestEngine.EngineId}]/[class:whatever]"))43 .filters(44 includeEngines(KotestJunitPlatformTestEngine.EngineId)45 )46 .build()47 val engine = KotestJunitPlatformTestEngine()48 shouldThrow<RuntimeException> {49 engine.discover(req, UniqueId.forEngine("testengine"))50 }51 }52 test("kotest should return classes if request includes kotest engine") {53 val req = LauncherDiscoveryRequestBuilder.request()54 .filters(55 includeEngines(KotestJunitPlatformTestEngine.EngineId)56 )57 .build()58 val engine = KotestJunitPlatformTestEngine()59 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))60 descriptor.classes.size shouldBe 2761 }62 test("kotest should return classes if request has no included or excluded test engines") {63 val req = LauncherDiscoveryRequestBuilder.request()64 .filters(65 PackageNameFilter.includePackageNames("com.sksamuel.kotest")66 )67 .build()68 val engine = KotestJunitPlatformTestEngine()69 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))70 descriptor.classes.size shouldBe 2571 }72 test("kotest should support include package name filter") {73 val req = LauncherDiscoveryRequestBuilder.request()74 .filters(75 PackageNameFilter.includePackageNames("com.sksamuel.kotest.runner.junit5.mypackage")76 )77 .build()78 val engine = KotestJunitPlatformTestEngine()79 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))80 descriptor.classes.map { it.qualifiedName } shouldBe listOf(81 "com.sksamuel.kotest.runner.junit5.mypackage.DummySpec1",82 "com.sksamuel.kotest.runner.junit5.mypackage.mysubpackage.DummySpec1",83 "com.sksamuel.kotest.runner.junit5.mypackage.DummySpec2",84 "com.sksamuel.kotest.runner.junit5.mypackage.mysubpackage.DummySpec2",85 )86 }87 test("kotest should return Nil if include package name filters matches nothing") {88 val req = LauncherDiscoveryRequestBuilder.request()89 .filters(90 PackageNameFilter.includePackageNames("com.sksamuel.kotest.runner.foobar")91 )92 .build()93 val engine = KotestJunitPlatformTestEngine()94 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))95 descriptor.classes.size shouldBe 096 }97 test("kotest should recognize fully qualified include class name filters") {98 val req = LauncherDiscoveryRequestBuilder.request()99 .filters(100 ClassNameFilter.includeClassNamePatterns(DiscoveryTest::class.java.canonicalName)101 )102 .build()103 val engine = KotestJunitPlatformTestEngine()104 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))105 descriptor.classes.map { it.qualifiedName } shouldBe listOf(DiscoveryTest::class.java.canonicalName)106 }107 test("kotest should return Nil if include class name filters have no matching values") {108 val req = LauncherDiscoveryRequestBuilder.request()109 .filters(110 ClassNameFilter.includeClassNamePatterns("Foo")111 )112 .build()113 val engine = KotestJunitPlatformTestEngine()114 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))115 descriptor.classes.size shouldBe 0116 }117 test("kotest should recognize prefixed class name filters") {118 val req = LauncherDiscoveryRequestBuilder.request()119 .filters(120 ClassNameFilter.includeClassNamePatterns(".*DiscoveryTest")121 )122 .build()123 val engine = KotestJunitPlatformTestEngine()124 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))125 descriptor.classes.size shouldBe 1126 }127 test("kotest should recognize suffixed class name pattern filters") {128 val req = LauncherDiscoveryRequestBuilder.request()129 .filters(130 ClassNameFilter.includeClassNamePatterns("com.sksamuel.kotest.runner.junit5.DiscoveryTe.*")131 )132 .build()133 val engine = KotestJunitPlatformTestEngine()134 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))135 descriptor.classes.size shouldBe 1136 }137 test("kotest should support excluded class name pattern filters") {138 val req = LauncherDiscoveryRequestBuilder.request()139 .filters(140 PackageNameFilter.includePackageNames("com.sksamuel.kotest.runner.junit5.mypackage"),141 ClassNameFilter.excludeClassNamePatterns(".*2")142 )143 .build()144 val engine = KotestJunitPlatformTestEngine()145 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))146 descriptor.classes.map { it.qualifiedName } shouldBe listOf(147 com.sksamuel.kotest.runner.junit5.mypackage.DummySpec1::class.java.canonicalName,148 com.sksamuel.kotest.runner.junit5.mypackage.mysubpackage.DummySpec1::class.java.canonicalName,149 )150 }151 test("kotest should support excluded fully qualified class name") {152 val req = LauncherDiscoveryRequestBuilder.request()153 .filters(154 PackageNameFilter.includePackageNames("com.sksamuel.kotest.runner.junit5.mypackage"),155 ClassNameFilter.excludeClassNamePatterns(com.sksamuel.kotest.runner.junit5.mypackage.DummySpec1::class.java.canonicalName)156 )157 .build()158 val engine = KotestJunitPlatformTestEngine()159 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))160 descriptor.classes.map { it.qualifiedName } shouldBe listOf(161 com.sksamuel.kotest.runner.junit5.mypackage.mysubpackage.DummySpec1::class.java.canonicalName,162 com.sksamuel.kotest.runner.junit5.mypackage.DummySpec2::class.java.canonicalName,163 com.sksamuel.kotest.runner.junit5.mypackage.mysubpackage.DummySpec2::class.java.canonicalName,164 )165 }166 test("kotest should support selected class names") {167 val req = LauncherDiscoveryRequestBuilder.request()168 .selectors(169 DiscoverySelectors.selectClass("com.sksamuel.kotest.runner.junit5.mypackage.DummySpec2")170 )171 .build()172 val engine = KotestJunitPlatformTestEngine()173 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))174 descriptor.classes.map { it.qualifiedName } shouldBe listOf(com.sksamuel.kotest.runner.junit5.mypackage.DummySpec2::class.java.canonicalName)175 }176 test("kotest should support multiple selected class names") {177 val req = LauncherDiscoveryRequestBuilder.request()178 .selectors(179 DiscoverySelectors.selectClass("com.sksamuel.kotest.runner.junit5.mypackage.DummySpec1"),180 DiscoverySelectors.selectClass("com.sksamuel.kotest.runner.junit5.mypackage.DummySpec2")181 )182 .build()183 val engine = KotestJunitPlatformTestEngine()184 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))185 descriptor.classes.map { it.qualifiedName } shouldBe listOf(186 com.sksamuel.kotest.runner.junit5.mypackage.DummySpec1::class.java.canonicalName,187 com.sksamuel.kotest.runner.junit5.mypackage.DummySpec2::class.java.canonicalName,188 )189 }190 test("package selector should include packages and subpackages") {191 val req = LauncherDiscoveryRequestBuilder.request()192 .selectors(193 DiscoverySelectors.selectPackage("com.sksamuel.kotest.runner.junit5.mypackage")194 )195 .build()196 val engine = KotestJunitPlatformTestEngine()197 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))198 descriptor.classes.map { it.qualifiedName } shouldBe listOf(199 com.sksamuel.kotest.runner.junit5.mypackage.DummySpec1::class.java.canonicalName,200 com.sksamuel.kotest.runner.junit5.mypackage.mysubpackage.DummySpec1::class.java.canonicalName,201 com.sksamuel.kotest.runner.junit5.mypackage.DummySpec2::class.java.canonicalName,202 com.sksamuel.kotest.runner.junit5.mypackage.mysubpackage.DummySpec2::class.java.canonicalName,203 )204 }205 test("discovery should support multiple package selectors") {206 val req = LauncherDiscoveryRequestBuilder.request()207 .selectors(208 DiscoverySelectors.selectPackage("com.sksamuel.kotest.runner.junit5.mypackage2"),209 DiscoverySelectors.selectPackage("com.sksamuel.kotest.runner.junit5.mypackage3")210 )211 .build()212 val engine = KotestJunitPlatformTestEngine()213 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))214 descriptor.classes.map { it.qualifiedName } shouldBe listOf(215 com.sksamuel.kotest.runner.junit5.mypackage2.DummySpec3::class.java.canonicalName,216 com.sksamuel.kotest.runner.junit5.mypackage2.DummySpec4::class.java.canonicalName,217 com.sksamuel.kotest.runner.junit5.mypackage3.DummySpec6::class.java.canonicalName,218 com.sksamuel.kotest.runner.junit5.mypackage3.DummySpec7::class.java.canonicalName,219 )220 }221 test("kotest should support mixed package and class selectors") {222 val req = LauncherDiscoveryRequestBuilder.request()223 .selectors(224 DiscoverySelectors.selectClass("com.sksamuel.kotest.runner.junit5.mypackage.DummySpec1"),225 DiscoverySelectors.selectPackage("com.sksamuel.kotest.runner.junit5.mypackage2")226 )227 .build()228 val engine = KotestJunitPlatformTestEngine()229 val descriptor = engine.discover(req, UniqueId.forEngine("testengine"))230 descriptor.classes.map { it.qualifiedName } shouldBe listOf(231 com.sksamuel.kotest.runner.junit5.mypackage.DummySpec1::class.java.canonicalName,232 com.sksamuel.kotest.runner.junit5.mypackage2.DummySpec3::class.java.canonicalName,233 com.sksamuel.kotest.runner.junit5.mypackage2.DummySpec4::class.java.canonicalName234 )235 }236 test("kotest should detect only public spec classes when internal flag is not set") {237 Discovery().discover(238 DiscoveryRequest(239 selectors = listOf(DiscoverySelector.PackageDiscoverySelector("com.sksamuel.kotest.runner.junit5.mypackage3")),240 filters = listOf(DiscoveryFilter.ClassModifierDiscoveryFilter(setOf(Modifier.Public)))241 )242 ).specs.map { it.simpleName }.toSet() shouldBe setOf("DummySpec7")243 }244 test("kotest should detect internal spec classes when internal flag is set") {245 Discovery().discover(246 DiscoveryRequest(247 selectors = listOf(DiscoverySelector.PackageDiscoverySelector("com.sksamuel.kotest.runner.junit5.mypackage3")),248 filters = listOf(DiscoveryFilter.ClassModifierDiscoveryFilter(setOf(Modifier.Public, Modifier.Internal)))249 )250 ).specs.map { it.simpleName }.toSet() shouldBe setOf("DummySpec6", "DummySpec7")251 }252 test("kotest should detect only internal specs if public is not set") {253 Discovery().discover(254 DiscoveryRequest(255 selectors = listOf(DiscoverySelector.PackageDiscoverySelector("com.sksamuel.kotest.runner.junit5.mypackage3")),256 filters = listOf(DiscoveryFilter.ClassModifierDiscoveryFilter(setOf(Modifier.Internal)))257 )258 ).specs.map { it.simpleName }.toSet() shouldBe setOf("DummySpec6")259 }260})...

Full Screen

Full Screen

uniqueids

Using AI Code Generation

copy

Full Screen

1import io.kotest.runner.junit.platform.UniqueIdSpec2class UniqueIdTest : UniqueIdSpec({3"this test should have a unique id" { }4})5import io.kotest.runner.junit5.UniqueIdSpec6class UniqueIdTest : UniqueIdSpec({7"this test should have a unique id" { }8})

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 uniqueids

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful