How to use String.capital method of io.kotest.engine.test.names.DefaultDisplayNameFormatter class

Best Kotest code snippet using io.kotest.engine.test.names.DefaultDisplayNameFormatter.String.capital

DefaultDisplayNameFormatter.kt

Source:DefaultDisplayNameFormatter.kt Github

copy

Full Screen

1package io.kotest.engine.test.names2import io.kotest.common.Platform3import io.kotest.common.platform4import io.kotest.core.annotation.displayname.wrapper5import io.kotest.core.config.ExtensionRegistry6import io.kotest.core.config.ProjectConfiguration7import io.kotest.core.extensions.DisplayNameFormatterExtension8import io.kotest.core.names.DisplayNameFormatter9import io.kotest.core.names.TestNameCase10import io.kotest.core.spec.DisplayName11import io.kotest.core.test.TestCase12import io.kotest.mpp.annotation13import io.kotest.mpp.bestName14import kotlin.reflect.KClass15fun getDisplayNameFormatter(registry: ExtensionRegistry, configuration: ProjectConfiguration): DisplayNameFormatter {16 return registry.all()17 .filterIsInstance<DisplayNameFormatterExtension>()18 .firstOrNull()19 ?.formatter() ?: DefaultDisplayNameFormatter(configuration)20}21/**22 * A default implementation of [DisplayNameFormatter].23 * Used when there are no registered [io.kotest.core.extensions.DisplayNameFormatterExtension]s.24 */25class DefaultDisplayNameFormatter(26 private val configuration: ProjectConfiguration,27) : DisplayNameFormatter {28 constructor() : this(ProjectConfiguration())29 override fun format(testCase: TestCase): String {30 val prefix = when (configuration.includeTestScopeAffixes ?: testCase.name.defaultAffixes) {31 true -> testCase.name.prefix ?: ""32 false -> ""33 }34 val suffix = when (configuration.includeTestScopeAffixes ?: testCase.name.defaultAffixes) {35 true -> testCase.name.suffix ?: ""36 false -> ""37 }38 val displayName = if (prefix.isBlank()) {39 when (configuration.testNameCase) {40 TestNameCase.Sentence -> testCase.name.testName.capital() + suffix41 TestNameCase.InitialLowercase -> testCase.name.testName.uncapitalize() + suffix42 TestNameCase.Lowercase -> testCase.name.testName.lowercase() + suffix43 else -> testCase.name.testName + suffix44 }45 } else {46 when (configuration.testNameCase) {47 TestNameCase.Sentence -> "${prefix.capital()}${testCase.name.testName.uncapitalize()}$suffix"48 TestNameCase.InitialLowercase -> "${prefix.uncapitalize()}${testCase.name.testName.uncapitalize()}$suffix"49 TestNameCase.Lowercase -> "${prefix.lowercase()}${testCase.name.testName.lowercase()}$suffix"50 else -> "$prefix${testCase.name.testName}$suffix"51 }52 }53 val name = if (configuration.testNameAppendTags) {54 return appendTagsInDisplayName(testCase, displayName)55 } else {56 displayName57 }58 return when (val parent = testCase.parent) {59 null -> name60 else -> if (configuration.displayFullTestPath) format(parent) + " " + name else name61 }62 }63 /**64 * Returns a formatted display name for this spec class.65 *66 * If the spec has been annotated with [DisplayName] (on supported platforms), then that will be used,67 * otherwise the default is to use the fully qualified class name.68 *69 * Note: This name must be globally unique. Two specs, even in different packages,70 * cannot share the same names, so if [DisplayName] is used, developers must ensure it does not71 * clash with another spec.72 */73 override fun format(kclass: KClass<*>): String {74 return when (platform) {75 Platform.JVM -> kclass.annotation<DisplayName>()?.wrapper ?: kclass.bestName()76 Platform.JS -> kclass.bestName()77 Platform.Native -> kclass.bestName()78 }79 }80}81fun appendTagsInDisplayName(testCase: TestCase, displayName: String): String {82 val tagNames = testCase.config.tags.joinToString(", ")83 return if (tagNames.isBlank()) {84 displayName85 } else {86 "${displayName}[tags = $tagNames]"87 }88}89private fun String.capital() = this.replaceFirstChar { if (it.isLowerCase()) it.titlecase() else it.toString() }90private fun String.uncapitalize() =91 this[0].lowercaseChar() + substring(1 until this.length)...

Full Screen

Full Screen

String.capital

Using AI Code Generation

copy

Full Screen

1val test1 = test("test1") { }2val test2 = test("test2") { }3val test3 = test("test3") { }4val test4 = test("test4") { }5val test5 = test("test5") { }6val test6 = test("test6") { }7val test7 = test("test7") { }8val test8 = test("test8") { }9val test9 = test("test9") { }10val test10 = test("test10") { }11val test11 = test("test11") { }12val test12 = test("test12") { }13val test13 = test("test13") { }14val test14 = test("test14") { }15val test15 = test("test15") { }16val test16 = test("test16") { }

Full Screen

Full Screen

String.capital

Using AI Code Generation

copy

Full Screen

1val test = TestName("testName")2val result = test.format()3println(result)4val test = TestName("testName")5val result = test.format()6println(result)7val test = TestName("testName")8val result = test.format()9println(result)10val test = TestName("testName")11val result = test.format()12println(result)13val test = TestName("testName")14val result = test.format()15println(result)16val test = TestName("testName")17val result = test.format()18println(result)19val test = TestName("testName")20val result = test.format()21println(result)22val test = TestName("testName")23val result = test.format()24println(result)25val test = TestName("testName")26val result = test.format()27println(result)28val test = TestName("testName")29val result = test.format()30println(result)31val test = TestName("testName")32val result = test.format()33println(result)

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