How to use createTestDescriptor method of io.kotest.runner.junit.platform.descriptors class

Best Kotest code snippet using io.kotest.runner.junit.platform.descriptors.createTestDescriptor

JUnitTestEngineListener.kt

Source:JUnitTestEngineListener.kt Github

copy

Full Screen

...168 startedTests.clear()169 }170 private fun addPlaceholderTest(parent: TestDescriptor, t: Throwable, kclass: KClass<*>) {171 val (name, cause) = ExtensionExceptionExtractor.resolve(t)172 val descriptor = createTestDescriptor(173 parent.uniqueId.append(Segment.Test.value, name),174 name,175 TestDescriptor.Type.TEST,176 ClassSource.from(kclass.java),177 false178 )179 parent.addChild(descriptor)180 listener.dynamicTestRegistered(descriptor)181 listener.executionStarted(descriptor)182 listener.executionFinished(descriptor, TestResult.Error(Duration.ZERO, cause).toTestExecutionResult())183 }184 override suspend fun testStarted(testCase: TestCase) {185 // depending on the test type, we may want to wait to notify junit, this is because gradle doesn't work186 // properly with the junit test types. Ideally, we'd just set everything to CONTAINER_AND_TEST, which is187 // supposed to mean a test can contain other tests as well as being a test itself, which is exactly how188 // Kotest views tests, but unfortunately it doesn't work properly.189 //190 // Another approach is to wait until the spec finishes to see which tests contain children and which191 // don't and set the test type appropriately, but junit doesn't give us a way to specify test duration192 // (instead it just calculates it itself from the time between marking a test as started and marking193 // it as finished), so this approach works but ends up having all tests as 0ms194 //195 // So the approach we will take is use the TestType from the test definition, unless it is dynamic,196 // then for dynamic we will calculate it later, and accept the 0ms drawback197 logger.log { Pair(testCase.name.testName, "test started") }198 if (testCase.parent != null) rootTests.add(testCase)199 addChild(testCase)200 when (testCase.type) {201 TestType.Container -> startTestIfNotStarted(testCase, TestDescriptor.Type.CONTAINER)202 TestType.Test -> startTestIfNotStarted(testCase, TestDescriptor.Type.TEST)203 TestType.Dynamic -> Unit204 }205 }206 // this test can be output now it has completed as we have all we need to know to complete it207 override suspend fun testFinished(testCase: TestCase, result: TestResult) {208 logger.log { Pair(testCase.name.testName, "test finished $result") }209 results[testCase.descriptor] = result210 val descriptor = getOrCreateTestDescriptor(testCase, null)211 // we need to ensure all parents have been started first212 startParents(testCase)213 startTestIfNotStarted(testCase, null)214 logger.log { Pair(testCase.name.testName, "executionFinished: $descriptor") }215 listener.executionFinished(descriptor, result.toTestExecutionResult())216 }217 override suspend fun testIgnored(testCase: TestCase, reason: String?) {218 logger.log { Pair(testCase.name.testName, "test ignored $reason") }219 if (testCase.parent == null) rootTests.add(testCase)220 addChild(testCase)221 results[testCase.descriptor] = TestResult.Ignored(reason)222 // we need to ensure all parents have been started first223 startParents(testCase)224 val descriptor = getOrCreateTestDescriptor(testCase, TestDescriptor.Type.TEST)225 logger.log { Pair(testCase.name.testName, "Registering dynamic test: $descriptor") }226 listener.dynamicTestRegistered(descriptor)227 logger.log { Pair(testCase.name.testName, "executionSkipped: $descriptor") }228 listener.executionSkipped(descriptor, reason)229 }230 private fun addChild(testCase: TestCase) {231 children.getOrPut(testCase.descriptor.parent) { mutableListOf() }.add(testCase)232 }233 private fun startParents(testCase: TestCase) {234 val parent = testCase.parent235 if (parent != null) {236 startParents(parent)237 startTestIfNotStarted(parent, null)238 }239 }240 private fun startTestIfNotStarted(testCase: TestCase, type: TestDescriptor.Type?) {241 if (!startedTests.contains(testCase.descriptor)) {242 val descriptor = getOrCreateTestDescriptor(testCase, type)243 logger.log { Pair(testCase.name.testName, "Registering dynamic test: $descriptor") }244 listener.dynamicTestRegistered(descriptor)245 logger.log { Pair(testCase.name.testName, "executionStarted: $descriptor") }246 listener.executionStarted(descriptor)247 startedTests.add(testCase.descriptor)248 }249 }250 private fun getOrCreateTestDescriptor(testCase: TestCase, type: TestDescriptor.Type?): TestDescriptor {251 val existing = descriptors[testCase.descriptor]252 if (existing != null) return existing253 val parent = when (val p = testCase.parent) {254 null -> getSpecDescriptor(testCase.spec::class)255 else -> getOrCreateTestDescriptor(p, null)256 }257 val id = parent.uniqueId.append(testCase.descriptor)258 // we dynamically work out the type if null by looking to see if this test had any children259 val c = children[testCase.descriptor]260 val t = when {261 type != null -> type262 c == null || c.isEmpty() -> TestDescriptor.Type.TEST263 else -> TestDescriptor.Type.CONTAINER264 }265 return createTestDescriptor(266 id,267 formatter.format(testCase),268 t,269 ClassSource.from(testCase.spec::class.java, null), // gradle-junit-platform hides tests if we don't send this270 type == TestDescriptor.Type.CONTAINER271 ).apply {272 parent.addChild(this)273 descriptors[testCase.descriptor] = this274 }275 }276 private fun getSpecDescriptor(kclass: KClass<*>): TestDescriptor {277 return getSpecDescriptor(root, kclass.toDescriptor(), formatter.format(kclass))278 }279 private fun createAndRegisterDummySpec(name: String): TestDescriptor {...

Full Screen

Full Screen

descriptors.kt

Source:descriptors.kt Github

copy

Full Screen

...37/**38 * Creates a [TestDescriptor] for the given [testCase] and attaches it to the [parent].39 * The created descriptor will have segment type [Segment.Test] and will use [displayName].40 */41fun createTestDescriptor(42 id: UniqueId,43 displayName: String,44 type: TestDescriptor.Type,45 source: TestSource?,46 mayRegisterTests: Boolean,47): TestDescriptor = object : AbstractTestDescriptor(id, displayName, source) {48 // there is a bug in gradle 4.7+ whereby CONTAINER_AND_TEST breaks test reporting or hangs the build, as it is not handled49 // see https://github.com/gradle/gradle/issues/491250 // so we can't use CONTAINER_AND_TEST for our test scopes, but simply container51 // update jan 2020: Seems we can use CONTAINER_AND_TEST now in gradle 6, and CONTAINER is invisible in output52 // update sep 2021: gradle 7.1 seems we can use TEST for everything but CONTAINER_AND_TEST will not show without a contained test53 // update for 5.0.0.M2 - will just dynamically add tests after they have completed, and we can see the full tree54 // update 5.0.0.M3 - if we add dynamically afterwards then the timings are all messed up, seems gradle keeps the time itself55 override fun getType(): TestDescriptor.Type = type...

Full Screen

Full Screen

PostDiscoveryFilterAdapter.kt

Source:PostDiscoveryFilterAdapter.kt Github

copy

Full Screen

...22 private val filter: PostDiscoveryFilter,23 private val uniqueId: UniqueId24) : TestFilter {25 override fun filter(descriptor: Descriptor): TestFilterResult {26 val testDescriptor = createTestDescriptor(uniqueId, descriptor, descriptor.id.value)27 return filter28 .toPredicate()29 .test(testDescriptor)30 .toTestFilterResult("Excluded by JUnit ClassMethodNameFilter: $filter")31 }32 /**33 * Creates a new [TestDescriptor] from the given Kotest [descriptor], chaining from34 * the [root] uniqueId. The [TestSource] is fudged since JUnit makes assumptions that tests are methods.35 * This descriptor is only used by the filter adapter.36 */37 private fun createTestDescriptor(root: UniqueId, descriptor: Descriptor, displayName: String): TestDescriptor {38 val id: UniqueId = descriptor.chain().fold(root) { acc, desc -> acc.append(desc) }39 val source = when (descriptor) {40 is Descriptor.SpecDescriptor -> ClassSource.from(descriptor.kclass.java)41 // this isn't a method, but we can use MethodSource with the test name, so it's at least42 // somewhat compatible for top level tests.43 is Descriptor.TestDescriptor -> MethodSource.from(descriptor.spec().kclass.java.name, descriptor.path().value)44 }45 return io.kotest.runner.junit.platform.createTestDescriptor(46 id,47 displayName,48 TestDescriptor.Type.CONTAINER,49 source,50 false51 )52 }53}...

Full Screen

Full Screen

createTestDescriptor

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.FunSpec2import io.kotest.core.test.TestCase3import io.kotest.core.test.TestResult4import io.kotest.matchers.shouldBe5import io.kotest.runner.junit.platform.descriptors.createTestDescriptor6import org.junit.platform.engine.TestDescriptor7import org.junit.platform.engine.TestSource8import org.junit.platform.engine.UniqueId9import org.junit.platform.engine.support.descriptor.EngineDescriptor10import org.junit.platform.engine.support.descriptor.FilePosition11import org.junit.platform.engine.support.descriptor.FileSource12import java.io.File13class MyTest : FunSpec() {14 init {15 test("test") {16 val test = createTestDescriptor(17 UniqueId.forEngine("test"),18 TestSource.from(File("file.txt")),19 FilePosition.from(1, 2),20 test.uniqueId.toString() shouldBe "test:name"21 test.source.get() shouldBe FileSource.from(File("file.txt"))22 test.sourcePosition.get() shouldBe FilePosition.from(1, 2)23 }24 }25}26import io.kotest.core.spec.style.FunSpec27import io.kotest.core.test.TestCase28import io.kotest.core.test.TestResult29import io.kotest.matchers.shouldBe30import io.kotest.runner.junit.platform.descriptors.createTestDescriptor31import org.junit.platform.engine.TestDescriptor32import org.junit.platform.engine.TestSource33import org.junit.platform.engine.UniqueId34import org.junit.platform.engine.support.descriptor.EngineDescriptor35import org.junit.platform.engine.support.descriptor.FilePosition36import org.junit.platform.engine.support.descriptor.FileSource37import java.io.File38class MyTest : FunSpec() {39 init {40 test("test") {41 val test = createTestDescriptor(42 UniqueId.forEngine("test"),43 TestSource.from(File("file.txt")),44 FilePosition.from(1, 2),45 test.uniqueId.toString() shouldBe "test:name"46 test.source.get() shouldBe FileSource.from(File("file.txt"))47 test.sourcePosition.get() shouldBe FilePosition.from(1, 2)48 }49 }50}

Full Screen

Full Screen

createTestDescriptor

Using AI Code Generation

copy

Full Screen

1val testDescriptor = createTestDescriptor( "test name" , "test display name" )2val testDescriptor = createTestDescriptor( "test name" , "test display name" , "test unique id" )3val testDescriptor = createTestDescriptor( "test name" , "test display name" , "test unique id" , "test source" )4val testDescriptor = createTestDescriptor( "test name" , "test display name" , "test unique id" , "test source" , "test class name" )5val testDescriptor = createTestDescriptor( "test name" , "test display name" , "test unique id" , "test source" , "test class name" , "test method name" )6val testDescriptor = createTestDescriptor( "test name" , "test display name" , "test unique id" , "test source" , "test class name" , "test method name" , "test class source" )7val testDescriptor = createTestDescriptor( "test name" , "test display name" , "test unique id" , "test source" , "test class name" , "test method name" , "test class source" , "test class unique id" )8val testDescriptor = createTestDescriptor( "test name" , "test display name" , "test unique id" , "test source" , "test class name" , "test method name" , "test class source" , "test class unique id" , "test parent name" )9val testDescriptor = createTestDescriptor( "test name" , "test display name" , "test unique

Full Screen

Full Screen

createTestDescriptor

Using AI Code Generation

copy

Full Screen

1val descriptor = createTestDescriptor( "some name" , "some unique id" , "some display name" )2val descriptor = createTestDescriptor( "some name" , "some unique id" , "some display name" , "some source" )3val descriptor = createTestDescriptor( "some name" , "some unique id" , "some display name" , "some source" , "some class name" )4val descriptor = createTestDescriptor( "some name" , "some unique id" , "some display name" , "some source" , "some class name" , "some method name" )5val descriptor = createTestDescriptor( "some name" , "some unique id" , "some display name" , "some source" , "some class name" , "some method name" , "some file name" )6val descriptor = createTestDescriptor( "some name" , "some unique id" , "some display name" , "some source" , "some class name" , "some method name" , "some file name" , "some line number" )7val descriptor = createTestDescriptor( "some name" , "some unique id" , "some display name" , "some source" , "some class name" , "some method name" , "some file name" , "some line number" , "some column number" )8val descriptor = createTestDescriptor( "some name" , "some unique id" , "some display name" , "some source" , "some class name" , "some method name" , "some file name" , "some line number" , "some column number" , "some package name" )

Full Screen

Full Screen

createTestDescriptor

Using AI Code Generation

copy

Full Screen

1val descriptor = createTestDescriptor("my test", "my test description", "my test source", "my test display name", "my test unique id", "my test class name")2val descriptor = createTestDescriptor("my test", "my test description", "my test source", "my test display name", "my test unique id", "my test class name", listOf("tag1", "tag2"))3val descriptor = createTestDescriptor("my test", "my test description", "my test source", "my test display name", "my test unique id", "my test class name", listOf("tag1", "tag2"), TestType.Container)4val descriptor = createTestDescriptor("my test", "my test description", "my test source", "my test display name", "my test unique id", "my test class name", listOf("tag1", "tag2"), TestType.Container)5val descriptor = createTestDescriptor("my test", "my test description", "my test source", "my test display name", "my test unique id", "my test class name", listOf("tag1", "tag2"), TestType.Container, "my test method")6val descriptor = createTestDescriptor("my test", "my test description", "my test source", "my test display name", "my test unique id", "my test class name", listOf("tag1", "tag2"), TestType.Container, "my test method", "my test instance")

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful