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

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

TeamCityMessageBuilder.kt

Source:TeamCityMessageBuilder.kt Github

copy

Full Screen

...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())...

Full Screen

Full Screen

TeamCityMessageBuilderTest.kt

Source:TeamCityMessageBuilderTest.kt Github

copy

Full Screen

...5import kotlin.time.Duration.Companion.milliseconds6class TeamCityMessageBuilderTest : ShouldSpec({7 should("escape brackets in messages") {8 val msg = TeamCityMessageBuilder.testFailed("testcity", "escape brackets")9 .message("expected:<[foo]> but was:<[bar]>")10 .duration(67.milliseconds)11 .build()12 msg shouldBe """testcity[testFailed name='escape brackets' message='expected:<|[foo|]> but was:<|[bar|]>' duration='67']"""13 }14 should("escape quotes in messages") {15 val msg = TeamCityMessageBuilder.testFailed("testcity", "escape quotes")16 .message("foo'bar")17 .duration(67.milliseconds)18 .build()19 msg shouldBe """testcity[testFailed name='escape quotes' message='foo|'bar' duration='67']"""20 }21 should("escape quotes in names") {22 val msg = TeamCityMessageBuilder.testFailed("testcity", "isn't busy")23 .message("foo'bar")24 .duration(67.milliseconds)25 .build()26 msg shouldBe """testcity[testFailed name='isn|'t busy' message='foo|'bar' duration='67']"""27 }28 should("escape new lines") {29 val msg = TeamCityMessageBuilder.testFailed("testcity", "escape brackets")30 .message(31 """32qweqwe33ewr34ret35"""36 )37 .duration(67.milliseconds)38 .build()39 msg shouldBe """testcity[testFailed name='escape brackets' message='qweqwe|newr|nret' duration='67']"""40 }41 should("support comparison values") {42 val msg = TeamCityMessageBuilder.testFailed("testcity", "support comparison values")43 .type("comparisonFailure")44 .message("test failed")45 .actual("act")46 .expected("exp")47 .duration(44.milliseconds)48 .build()49 msg shouldBe """testcity[testFailed name='support comparison values' type='comparisonFailure' message='test failed' actual='act' expected='exp' duration='44']"""50 }51})...

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