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

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

JUnitTestEngineListener.kt

Source:JUnitTestEngineListener.kt Github

copy

Full Screen

...11import io.kotest.engine.errors.ExtensionExceptionExtractor12import io.kotest.engine.interceptors.EngineContext13import io.kotest.engine.listener.AbstractTestEngineListener14import io.kotest.engine.test.names.DefaultDisplayNameFormatter15import io.kotest.engine.test.names.getDisplayNameFormatter16import io.kotest.mpp.Logger17import io.kotest.mpp.bestName18import org.junit.platform.engine.EngineExecutionListener19import org.junit.platform.engine.TestDescriptor20import org.junit.platform.engine.TestExecutionResult21import org.junit.platform.engine.support.descriptor.ClassSource22import org.junit.platform.engine.support.descriptor.EngineDescriptor23import kotlin.reflect.KClass24import kotlin.time.Duration25/**26 * Notifies JUnit Platform of test statuses via a [EngineExecutionListener].27 *28 * This is not thread safe and should only be invoked by one spec at a time.29 *30 * JUnit platform supports out of order notification of tests, in that sibling31 * tests can be executing in parallel and updating JUnit out of order. However the gradle test32 * task gets confused if we are executing two or more tests directly under the root at once.33 * Therefore we must queue up notifications until each spec is completed.34 *35 * Gradle test run observations:36 *37 * using Platform 1.6.0 --38 * TestDescriptor.Type.CONTAINER seem to be ignored in output.39 * TestDescriptor.Type.CONTAINER_AND_TEST appear as siblings of their nested tests if not added as a child40 * Add child first, then register dynamic test, then start the test41 *42 * Top level descriptors must have a source attached or the execution will fail with a parent attached exception.43 * Type.CONTAINER_TEST doesn't seem to work as a top level descriptor, it will hang44 * leaf tests do not need to be completed but they will be marked as uncomplete in intellij.45 * Dynamic test can be called after or before addChild.46 * A Type.TEST can be a child of a Type.TEST.47 * Intermediate Type.CONTAINER seem to be ignored in output.48 * Intermediate containers can have same class source as parent.49 * Type.TEST as top level seems to hang.50 * A TEST doesn't seem to be able to have the same source as a parent, or hang.51 * A TEST seems to hang if it has a ClassSource.52 * MethodSource seems to be ok with a TEST.53 * Container test names seem to be taken from a Source.54 * Nested tests are outputted as siblings.55 * Can complete executions out of order.56 * Child failures will fail parent CONTAINER.57 * Sibling containers can start and finish in parallel.58 *59 * Intellij runner observations:60 *61 * Intermediate Type.CONTAINERs are shown.62 * Intermediate Type.TESTs are shown.63 * A Type.TEST can be a child of a Type.TEST64 * MethodSource seems to be ok with a TEST.65 * Container test names seem to be taken from the name property.66 * Nested tests are outputted as nested.67 * Child failures will not fail containing TEST.68 * child failures will fail a containing CONTAINER.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)92 }93 override suspend fun engineInitialized(context: EngineContext) {94 failOnIgnoredTests = context.configuration.failOnIgnoredTests95 formatter = getDisplayNameFormatter(context.configuration.registry, context.configuration)96 }97 override suspend fun engineFinished(t: List<Throwable>) {98 logger.log { Pair(null, "Engine finished; throwables=[${t}]") }99 registerExceptionPlaceholders(t)100 val result = if (failOnIgnoredTests && results.values.any { it.isIgnored }) {101 TestExecutionResult.failed(RuntimeException("Build contained ignored test"))102 } else {103 TestExecutionResult.successful()104 }105 logger.log { Pair(null, "Notifying junit that engine completed $root") }106 listener.executionFinished(root, result)107 }108 override suspend fun specStarted(kclass: KClass<*>) {109 markSpecStarted(kclass)...

Full Screen

Full Screen

TeamCityTestEngineListener.kt

Source:TeamCityTestEngineListener.kt Github

copy

Full Screen

...11import io.kotest.engine.interceptors.EngineContext12import io.kotest.engine.teamcity.Locations13import io.kotest.engine.teamcity.TeamCityMessageBuilder14import io.kotest.engine.test.names.DefaultDisplayNameFormatter15import io.kotest.engine.test.names.getDisplayNameFormatter16import io.kotest.mpp.bestName17import kotlin.reflect.KClass18/**19 * A [TestEngineListener] that logs events to the console using a [TeamCityMessageBuilder].20 */21class TeamCityTestEngineListener(22 private val prefix: String = TeamCityMessageBuilder.TeamCityPrefix,23 private val details: Boolean = true,24) : TestEngineListener {25 private var formatter: DisplayNameFormatter = DefaultDisplayNameFormatter(ProjectConfiguration())26 // once a spec has completed, we want to be able to check whether any given test is27 // a container or a leaf test, and so this map contains all test that have children28 private val children = mutableMapOf<Descriptor, MutableList<TestCase>>()29 private val results = mutableMapOf<Descriptor, TestResult>()30 private val started = mutableSetOf<Descriptor.TestDescriptor>()31 // intellij has no method for failed suites, so if a container or spec fails we must insert32 // a dummy "test" in order to tag the error against that33 private fun insertPlaceholder(t: Throwable, parent: Descriptor) {34 val (name, cause) = ExtensionExceptionExtractor.resolve(t)35 val msg1 = TeamCityMessageBuilder36 .testStarted(prefix, name)37 .id(name)38 .parent(parent.path().value)39 .build()40 println(msg1)41 // we must print out the stack trace in between the dummy, so it appears when you click on the test name42 //t?.printStackTrace()43 val msg2 = TeamCityMessageBuilder44 .testFailed(prefix, name)45 .id(name)46 .parent(parent.path().value)47 .withException(cause, details)48 .build()49 println(msg2)50 val msg3 = TeamCityMessageBuilder51 .testFinished(prefix, name)52 .id(name)53 .parent(parent.path().value)54 .build()55 println(msg3)56 }57 override suspend fun engineStarted() {}58 override suspend fun engineInitialized(context: EngineContext) {59 formatter = getDisplayNameFormatter(context.configuration.registry, context.configuration)60 }61 override suspend fun engineFinished(t: List<Throwable>) {62 if (t.isNotEmpty()) {63 t.withIndex().forEach { (index, error) ->64 val testName = if (t.size == 1) "Engine exception" else "Engine exception ${index + 1}"65 println(TeamCityMessageBuilder.testStarted(prefix, testName).build())66 val message = error.message ?: t::class.bestName()67 println(TeamCityMessageBuilder.testFailed(prefix, testName).message(message).build())68 println(TeamCityMessageBuilder.testFinished(prefix, testName).build())69 }70 }71 }72 override suspend fun specStarted(kclass: KClass<*>) {73 val msg = TeamCityMessageBuilder...

Full Screen

Full Screen

EnhancedConsoleTestEngineListener.kt

Source:EnhancedConsoleTestEngineListener.kt Github

copy

Full Screen

...9import io.kotest.core.test.TestType10import io.kotest.engine.interceptors.EngineContext11import io.kotest.engine.test.names.DefaultDisplayNameFormatter12import io.kotest.engine.test.names.formatTestPath13import io.kotest.engine.test.names.getDisplayNameFormatter14import kotlin.reflect.KClass15import kotlin.time.Duration16/**17 * Generates test output to the console in an enhanced, formatted, coloured, way.18 * For a more basic output, see [BasicConsoleTestEngineListener]19 */20class EnhancedConsoleTestEngineListener(private val term: TermColors) : AbstractTestEngineListener() {21 private var errors = 022 private var start = System.currentTimeMillis()23 private var testsFailed = emptyList<Pair<TestCase, TestResult>>()24 private var testsIgnored = 025 private var testsPassed = 026 private var specsFailed = emptyList<Descriptor.SpecDescriptor>()27 private var specsSeen = emptyList<Descriptor>()28 private var slow = Duration.milliseconds(500)29 private var verySlow = Duration.milliseconds(5000)30 private var formatter:DisplayNameFormatter = DefaultDisplayNameFormatter(ProjectConfiguration())31 private fun green(str: String) = term.green(str)32 private fun greenBold(str: String) = term.green.plus(term.bold).invoke(str)33 private fun red(str: String) = term.red(str)34 private fun brightRed(str: String) = term.brightRed(str)35 private fun brightRedBold(str: String) = term.brightRed.plus(term.bold).invoke(str)36 private fun redBold(str: String) = term.red.plus(term.bold).invoke(str)37 private fun yellow(str: String) = term.yellow(str)38 private fun brightYellow(str: String) = term.brightYellow(str)39 private fun brightYellowBold(str: String) = term.brightYellow.plus(term.bold).invoke(str)40 private fun yellowBold(str: String) = term.yellow.plus(term.bold).invoke(str)41 private fun bold(str: String) = term.bold(str)42 private val intros = listOf(43 "Feeding the kotest engine with freshly harvested tests",44 "Engaging kotest engine at warp factor 9",45 "Harvesting the test fields",46 "Preparing to sacrifice your code to the demi-god of test",47 "Hamsters are turning the wheels of kotest",48 "Battle commanders are ready to declare war on bugs",49 "Be afraid - be very afraid - of failing tests",50 "The point is, ladies and gentlemen, that green is good",51 "Lock test-foils in attack position",52 "Fasten your seatbelts. It's going to be a bumpy test-run",53 "Lets crack open this test suite",54 "Lets get testing, I'm on the clock here",55 "Test time is the best time",56 "Open the test suite doors, HAL",57 "Mama always said testing was like a box of chocolates. You don't know which ones are gonna fail",58 "A test suite. Shaken, not stirred",59 "I'm going to make him a test he can't refuse",60 "You testing me? I don't see any other tests here, so you must be testing me",61 "I love the smell of tests in the morning",62 "Do you feel lucky punk? Do you think your tests will pass? Well, do ya?",63 "Mirab, with tests unfurled",64 "Dolly works 9 to 5. I test 24/7",65 "A test suite's gotta do what a test suite's gotta do",66 "I test code and chew bubblegum, and I'm all out of bubblegum"67 )68 override suspend fun engineInitialized(context: EngineContext) {69 formatter = getDisplayNameFormatter(context.configuration.registry, context.configuration)70 println(bold(">> Kotest"))71 println("- " + intros.shuffled().first())72 print("- Test plan has ")73 print(greenBold(context.suite.specs.size.toString()))74 println(" specs")75 println()76 }77 override suspend fun engineFinished(t: List<Throwable>) {78 if (specsSeen.isEmpty()) return79 if (t.isNotEmpty()) {80 errors += t.size81 t.forEach {82 printThrowable(it, 0)83 }...

Full Screen

Full Screen

DefaultDisplayNameFormatter.kt

Source:DefaultDisplayNameFormatter.kt Github

copy

Full Screen

...11import 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 {...

Full Screen

Full Screen

getDisplayNameFormatter

Using AI Code Generation

copy

Full Screen

1val formatter = DefaultDisplayNameFormatter()2formatter.getDisplayNameFormatter().invoke(testCase)3val formatter = TestNameDisplayNameFormatter()4formatter.getDisplayNameFormatter().invoke(testCase)5val formatter = TestPathDisplayNameFormatter()6formatter.getDisplayNameFormatter().invoke(testCase)7val formatter = TestPathWithHashcodeDisplayNameFormatter()8formatter.getDisplayNameFormatter().invoke(testCase)9val formatter = TestPathWithHashcodeAndOrderDisplayNameFormatter()10formatter.getDisplayNameFormatter().invoke(testCase)11val formatter = TestPathWithHashcodeAndOrderDisplayNameFormatter()12formatter.getDisplayNameFormatter().invoke(testCase)13val formatter = TestPathWithHashcodeAndOrderDisplayNameFormatter()14formatter.getDisplayNameFormatter().invoke(testCase)15val formatter = TestPathWithHashcodeAndOrderDisplayNameFormatter()16formatter.getDisplayNameFormatter().invoke(testCase)17val formatter = TestPathWithHashcodeAndOrderDisplayNameFormatter()18formatter.getDisplayNameFormatter().invoke(testCase)19val formatter = TestPathWithHashcodeAndOrderDisplayNameFormatter()20formatter.getDisplayNameFormatter().invoke(testCase)21val formatter = TestPathWithHashcodeAndOrderDisplayNameFormatter()22formatter.getDisplayNameFormatter().invoke(testCase)

Full Screen

Full Screen

getDisplayNameFormatter

Using AI Code Generation

copy

Full Screen

1val formatter = DefaultDisplayNameFormatter()2formatter.getDisplayNameFormatter()3val formatter = DefaultDisplayNameFormatter()4formatter.getDisplayNameFormatter()5val formatter = DefaultDisplayNameFormatter()6formatter.getDisplayNameFormatter()7val formatter = DefaultDisplayNameFormatter()8formatter.getDisplayNameFormatter()9val formatter = DefaultDisplayNameFormatter()10formatter.getDisplayNameFormatter()11val formatter = DefaultDisplayNameFormatter()12formatter.getDisplayNameFormatter()13val formatter = DefaultDisplayNameFormatter()14formatter.getDisplayNameFormatter()15val formatter = DefaultDisplayNameFormatter()16formatter.getDisplayNameFormatter()17val formatter = DefaultDisplayNameFormatter()18formatter.getDisplayNameFormatter()19val formatter = DefaultDisplayNameFormatter()20formatter.getDisplayNameFormatter()21val formatter = DefaultDisplayNameFormatter()22formatter.getDisplayNameFormatter()23val formatter = DefaultDisplayNameFormatter()24formatter.getDisplayNameFormatter()25val formatter = DefaultDisplayNameFormatter()26formatter.getDisplayNameFormatter()27val formatter = DefaultDisplayNameFormatter()28formatter.getDisplayNameFormatter()29val formatter = DefaultDisplayNameFormatter()30formatter.getDisplayNameFormatter()31val formatter = DefaultDisplayNameFormatter()32formatter.getDisplayNameFormatter()33val formatter = DefaultDisplayNameFormatter()34formatter.getDisplayNameFormatter()35val formatter = DefaultDisplayNameFormatter()36formatter.getDisplayNameFormatter()37val formatter = DefaultDisplayNameFormatter()38formatter.getDisplayNameFormatter()39val formatter = DefaultDisplayNameFormatter()40formatter.getDisplayNameFormatter()41val formatter = DefaultDisplayNameFormatter()42formatter.getDisplayNameFormatter()

Full Screen

Full Screen

getDisplayNameFormatter

Using AI Code Generation

copy

Full Screen

1val formatter = DefaultDisplayNameFormatter()2val displayName = formatter.getDisplayNameFormatter(testCase)3val formatter = DefaultDisplayNameFormatter()4val displayName = formatter.getDisplayNameFormatter(testCase)5val formatter = DefaultDisplayNameFormatter()6val displayName = formatter.getDisplayNameFormatter(testCase)7val formatter = DefaultDisplayNameFormatter()8val displayName = formatter.getDisplayNameFormatter(testCase)9val formatter = DefaultDisplayNameFormatter()10val displayName = formatter.getDisplayNameFormatter(testCase)11val formatter = DefaultDisplayNameFormatter()12val displayName = formatter.getDisplayNameFormatter(testCase)13val formatter = DefaultDisplayNameFormatter()14val displayName = formatter.getDisplayNameFormatter(testCase)15val formatter = DefaultDisplayNameFormatter()16val displayName = formatter.getDisplayNameFormatter(testCase)17val formatter = DefaultDisplayNameFormatter()18val displayName = formatter.getDisplayNameFormatter(testCase)19val formatter = DefaultDisplayNameFormatter()20val displayName = formatter.getDisplayNameFormatter(testCase)

Full Screen

Full Screen

getDisplayNameFormatter

Using AI Code Generation

copy

Full Screen

1val displayNameFormatter = DefaultDisplayNameFormatter()2val displayName = displayNameFormatter.formatDisplayName(testCase)3println(displayName)4val displayNameFormatter = TestNameFormatter()5val displayName = displayNameFormatter.formatDisplayName(testCase)6println(displayName)7val displayNameFormatter = object : DisplayNameFormatter {8override fun formatDisplayName(testCase: TestCase): String {9}10}11val displayName = displayNameFormatter.formatDisplayName(testCase)12println(displayName)13val description = Description.createTestDescription(testCase.spec::class.java, testCase.name.testName)14println(displayName)15val displayName = DisplayName.getDisplayName(testCase.name.testName)16println(displayName)17val nameInfo = NameInfo(testCase.name.testName)18println(displayName)19val testResult = TestResult()20testResult.setName(testCase.name.testName)21val displayName = testResult.getDisplayName()22println(displayName)

Full Screen

Full Screen

getDisplayNameFormatter

Using AI Code Generation

copy

Full Screen

1val formatter = DefaultDisplayNameFormatter()2val displayName = formatter.getDisplayNameFormatter(testCase)3println("DisplayName: $displayName")4}5}6fun main() {7val testCase = TestCase(8TestName("Test case"),9TestPath(emptyList()),10emptyList(),11emptyMap(),

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