Best Kotest code snippet using io.kotest.core.descriptors.SpecDescriptor.depth
EnhancedConsoleTestEngineListener.kt
Source:EnhancedConsoleTestEngineListener.kt
...164 println()165 }166 override suspend fun testIgnored(testCase: TestCase, reason: String?) {167 testsIgnored++168 print("".padEnd(testCase.descriptor.depth() * 4, ' '))169 print("- " + formatter.format(testCase))170 println(brightYellowBold(" IGNORED"))171 }172 private fun durationString(duration: Duration): String {173 return when {174 duration in slow..verySlow -> term.brightYellow("(${duration.inWholeMilliseconds}ms)")175 duration > verySlow -> term.brightRed("(${duration.inWholeMilliseconds}ms)")176 else -> ""177 }178 }179 override suspend fun testFinished(testCase: TestCase, result: TestResult) {180 // only leaf tests or failed containers contribute to the counts181 when (result) {182 is TestResult.Success -> if (testCase.type == TestType.Test) testsPassed++183 is TestResult.Failure, is TestResult.Error -> {184 errors++185 testsFailed = testsFailed + Pair(testCase, result)186 specsFailed = specsFailed + testCase.descriptor.spec()187 }188 else -> Unit189 }190 // we only print the name and status for leafs, as containers are printed in advance191 if (testCase.type == TestType.Test) {192 print("".padEnd(testCase.descriptor.depth() * 4, ' '))193 print("- " + formatter.format(testCase))194 when (result) {195 is TestResult.Success -> print(greenBold(" OK"))196 is TestResult.Error -> print(brightRed(" ERROR"))197 is TestResult.Failure -> print(brightRed(" FAILED"))198 is TestResult.Ignored -> print(brightYellow(" IGNORED"))199 }200 if (result.duration > slow) {201 print(" ${durationString(result.duration)}")202 }203 println()204 }205 if (result.errorOrNull != null) {206 println()207 printThrowable(result.errorOrNull, testCase.descriptor.depth() * 4)208 println()209 }210 }211 override suspend fun testStarted(testCase: TestCase) {212 // containers we display straight away without pass / fail message213 if (testCase.type == TestType.Container) {214 print("".padEnd(testCase.descriptor.depth() * 4, ' '))215 println("+ " + formatter.format(testCase))216 }217 }218}...
descriptor.kt
Source:descriptor.kt
...67 * Returns true if this descriptor represents a root test case.68 */69 fun isRootTest() = this is TestDescriptor && this.parent.isSpec()70 /**71 * Returns the depth of this node, where the [SpecDescriptor] has depth of 0,72 * a root test has depth 1 and so on.73 */74 fun depth() = parents().size - 175 /**76 * Recursively returns any parent descriptors, with the spec being first in the list77 * and this being last.78 */79 fun parents(): List<Descriptor> = when (this) {80 is SpecDescriptor -> emptyList()81 is TestDescriptor -> parent.parents() + parent82 }83 fun chain() = parents() + this84 /**85 * Returns true if this descriptor is the immediate parent of the given [descriptor].86 */87 fun isParentOf(descriptor: Descriptor): Boolean = when (descriptor) {88 is SpecDescriptor -> false // nothing can be the parent of a spec...
depth
Using AI Code Generation
1val specDescriptor = SpecDescriptor ( "MySpec" , "com.example" , "com.example.MySpec" , "com.example.MySpec" , "MySpec" , "com.example" , "com.example.MySpec" )2val specDescriptor = SpecDescriptor ( "MySpec" , "com.example" , "com.example.MySpec" , "com.example.MySpec" , "MySpec" , "com.example" , "com.example.MySpec" )3val specDescriptor = SpecDescriptor ( "MySpec" , "com.example" , "com.example.MySpec" , "com.example.MySpec" , "MySpec" , "com.example" , "com.example.MySpec" )4val specDescriptor = SpecDescriptor ( "MySpec" , "com.example" , "com.example.MySpec" , "com.example.MySpec" , "MySpec" , "com.example" , "com.example.MySpec" )5val specDescriptor = SpecDescriptor ( "MySpec" , "com.example" , "com.example.MySpec" , "com.example.MySpec" , "MySpec" , "com.example" , "com.example.MySpec" )6val specDescriptor = SpecDescriptor ( "MySpec" , "com.example" , "com.example.MySpec" , "com.example.MySpec" , "MySpec" , "com.example" , "com.example.MySpec" )7val specDescriptor = SpecDescriptor ( "MySpec" , "com.example" , "com.example.MySpec" , "com.example.MySpec" , "MySpec" , "com.example" , "com.example.MySpec" )8val specDescriptor = SpecDescriptor ( "MySpec" , "com.example" , "com.example.MySpec" , "com.example.MySpec" , "MySpec" ,
depth
Using AI Code Generation
1val descriptor = SpecDescriptor( "MySpec" , "com.example" , 1 , 2 , 3 )2val descriptor2 = descriptor.append( "MyTest" )3val descriptor3 = descriptor.append( "MyTest" , 1 )4val descriptor4 = descriptor.append( "MyTest" , 1 , 2 )5val descriptor5 = descriptor.append( "MyTest" , 1 , 2 , 3 )6val descriptor6 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 )7val descriptor7 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 )8val descriptor8 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 , 6 )9val descriptor9 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 , 6 , 7 )10val descriptor10 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 )11val descriptor11 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )12val descriptor12 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 )13val descriptor13 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 )14val descriptor14 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 )15val descriptor15 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 )16val descriptor16 = descriptor.append( "MyTest" , 1 , 2 , 3 , 4 , 5 , 6 , 7
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!!