How to use addAttribute method of io.kotest.engine.teamcity.TeamCityMessageBuilder class

Best Kotest code snippet using io.kotest.engine.teamcity.TeamCityMessageBuilder.addAttribute

TeamCityMessageBuilder.kt

Source:TeamCityMessageBuilder.kt Github

copy

Full Screen

...32 companion object {33 const val TeamCityPrefix = "##teamcity"34 fun testSuiteStarted(name: String): TeamCityMessageBuilder = testSuiteStarted(TeamCityPrefix, name)35 fun testSuiteStarted(prefix: String, name: String): TeamCityMessageBuilder {36 return TeamCityMessageBuilder(prefix, Messages.TEST_SUITE_STARTED).addAttribute(Attributes.NAME, name)37 }38 fun testSuiteFinished(name: String): TeamCityMessageBuilder = testSuiteFinished(TeamCityPrefix, name)39 fun testSuiteFinished(prefix: String, name: String): TeamCityMessageBuilder {40 return TeamCityMessageBuilder(prefix, Messages.TEST_SUITE_FINISHED).addAttribute(Attributes.NAME, name)41 }42 fun testStarted(name: String): TeamCityMessageBuilder = testStarted(TeamCityPrefix, name)43 fun testStarted(prefix: String, name: String): TeamCityMessageBuilder {44 return TeamCityMessageBuilder(prefix, Messages.TEST_STARTED).addAttribute(Attributes.NAME, name)45 }46 fun testFinished(name: String): TeamCityMessageBuilder = testFinished(TeamCityPrefix, name)47 fun testFinished(prefix: String, name: String): TeamCityMessageBuilder {48 return TeamCityMessageBuilder(prefix, Messages.TEST_FINISHED).addAttribute(Attributes.NAME, name)49 }50 fun testStdOut(name: String): TeamCityMessageBuilder = testStdOut(TeamCityPrefix, name)51 fun testStdOut(prefix: String, name: String): TeamCityMessageBuilder {52 return TeamCityMessageBuilder(prefix, Messages.TEST_STD_OUT).addAttribute(Attributes.NAME, name)53 }54 fun testStdErr(name: String): TeamCityMessageBuilder = testStdErr(TeamCityPrefix, name)55 fun testStdErr(prefix: String, name: String): TeamCityMessageBuilder {56 return TeamCityMessageBuilder(prefix, Messages.TEST_STD_ERR).addAttribute(Attributes.NAME, name)57 }58 // note it seems that not attaching a message renders test failed irrelevant59 fun testFailed(name: String): TeamCityMessageBuilder = testFailed(TeamCityPrefix, name)60 // note it seems that not attaching a message renders test failed irrelevant61 fun testFailed(prefix: String, name: String): TeamCityMessageBuilder {62 return TeamCityMessageBuilder(prefix, Messages.TEST_FAILED).addAttribute(Attributes.NAME, name)63 }64 fun testIgnored(name: String): TeamCityMessageBuilder = testIgnored(TeamCityPrefix, name)65 fun testIgnored(prefix: String, name: String): TeamCityMessageBuilder {66 return TeamCityMessageBuilder(prefix, Messages.TEST_IGNORED).addAttribute(Attributes.NAME, name)67 }68 }69 object Attributes {70 const val ACTUAL = "actual"71 const val EXPECTED = "expected"72 const val LOCATION_HINT = "locationHint"73 const val NAME = "name"74 const val DURATION = "duration"75 const val TIMESTAMP = "timestamp"76 const val TYPE = "type"77 const val DETAILS = "details"78 const val MESSAGE = "message"79 const val PARENT_ID = "parent_id"80 const val ID = "id"81 const val RESULT_STATUS = "result_status"82 }83 object Messages {84 const val TEST_SUITE_STARTED = "testSuiteStarted"85 const val TEST_SUITE_FINISHED = "testSuiteFinished"86 const val TEST_STARTED = "testStarted"87 const val TEST_FINISHED = "testFinished"88 const val TEST_IGNORED = "testIgnored"89 const val TEST_STD_OUT = "testStdOut"90 const val TEST_STD_ERR = "testStdErr"91 const val TEST_FAILED = "testFailed"92 }93 private val myText = StringBuilder(prefix).append("[$messageName")94 fun addAttribute(name: String, value: String): TeamCityMessageBuilder {95 myText96 .append(' ')97 .append(name).append("='")98 .append(Escaper.escapeForTeamCity(value))99 .append("'")100 return this101 }102 fun message(value: String?): TeamCityMessageBuilder =103 if (value != null) addAttribute(Attributes.MESSAGE, value.trim()) else this104 fun details(value: String?): TeamCityMessageBuilder =105 if (value != null) addAttribute(Attributes.DETAILS, value.trim()) else this106 fun type(value: String): TeamCityMessageBuilder = addAttribute(Attributes.TYPE, value.trim())107 fun actual(value: String): TeamCityMessageBuilder = addAttribute(Attributes.ACTUAL, value.trim())108 fun expected(value: String): TeamCityMessageBuilder = addAttribute(Attributes.EXPECTED, value.trim())109 fun result(value: TestResult): TeamCityMessageBuilder = addAttribute(Attributes.RESULT_STATUS, value.name)110 fun locationHint(value: String?): TeamCityMessageBuilder =111 if (value != null) addAttribute(Attributes.LOCATION_HINT, value) else this112 // note it seems that not attaching a message renders test failed irrelevant113 fun withException(error: Throwable?, showDetails: Boolean = true): TeamCityMessageBuilder {114 if (error == null) return this115 val line1 = error.message?.trim()?.lines()?.firstOrNull()116 val message = if (line1.isNullOrBlank()) "Test failed" else line1117 message(escapeColons(message))118 if (showDetails)119 details(escapeColons(error.stackTraceToString()))120 when (error) {121 is ComparisonError -> type("comparisonFailure").actual(error.actualValue).expected(error.expectedValue)122 }123 return this124 }125 // sets the test's parents id126 fun parent(value: String): TeamCityMessageBuilder = addAttribute(Attributes.PARENT_ID, value)127 // sets a unique parsable id for this test128 fun id(value: String): TeamCityMessageBuilder = addAttribute(Attributes.ID, value)129 // workaround for TC colon issue, see main javadoc130 fun escapeColons(value: String) = when (escapeColons) {131 true -> value.replace(":", "\u02D0")132 false -> value133 }134 fun duration(duration: Duration): TeamCityMessageBuilder =135 addAttribute(Attributes.DURATION, duration.inWholeMilliseconds.toString())136 /**137 * Returns the completed string.138 */139 fun build(): String = "$myText]"140 fun timestamp(ts: String) = addAttribute(Attributes.TIMESTAMP, ts)141}...

Full Screen

Full Screen

addAttribute

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.StringSpec2class TeamCityMessageBuilderExample : StringSpec({3 "add custom message to TeamCity console output" {4 addAttribute("customMessage", "this is a custom message")5 }6})7import io.kotest.core.spec.style.StringSpec8class TeamCityMessageBuilderExample : StringSpec({9 "add custom message to TeamCity console output" {10 addAttribute("customMessage", "this is a custom message")11 }12})13import io.kotest.core.spec.style.StringSpec14class TeamCityMessageBuilderExample : StringSpec({15 "add custom message to TeamCity console output" {16 addAttribute("customMessage", "this is a custom message")17 }18})19import io.kotest.core.spec.style.StringSpec20class TeamCityMessageBuilderExample : StringSpec({21 "add custom message to TeamCity console output" {22 addAttribute("customMessage", "this is a custom message")23 }24})25import io.kotest.core.spec.style.StringSpec26class TeamCityMessageBuilderExample : StringSpec({27 "add custom message to TeamCity console output" {28 addAttribute("customMessage", "this is a custom message")29 }30})

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