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

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

TeamCityTestEngineListener.kt

Source:TeamCityTestEngineListener.kt Github

copy

Full Screen

...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 = TeamCityMessageBuilder74 .testSuiteStarted(prefix, formatter.format(kclass))75 .id(kclass.toDescriptor().path().value)76 .locationHint(Locations.location(kclass))77 .build()78 println(msg)79 }80 // ignored specs are completely hidden from output in team city81 override suspend fun specIgnored(kclass: KClass<*>, reason: String?) {}82 override suspend fun specFinished(kclass: KClass<*>, result: TestResult) {83 // if the spec itself has an error, we must insert a placeholder test84 when (val t = result.errorOrNull) {85 null -> Unit86 is MultipleExceptions -> t.causes.forEach { insertPlaceholder(it, kclass.toDescriptor()) }87 else -> insertPlaceholder(t, kclass.toDescriptor())88 }89 finishSpec(kclass)90 results.clear()91 children.clear()92 }93 private fun finishSpec(kclass: KClass<*>) {94 val msg = TeamCityMessageBuilder95 .testSuiteFinished(prefix, formatter.format(kclass))96 .id(kclass.toDescriptor().path().value)97 .locationHint(Locations.location(kclass))98 .build()99 println(msg)100 }101 override suspend fun testStarted(testCase: TestCase) {102 if (testCase.parent != null) addChild(testCase)103 when (testCase.type) {104 TestType.Container -> startTestSuite(testCase)105 TestType.Test -> startTest(testCase)106 TestType.Dynamic -> Unit107 }108 }109 override suspend fun testIgnored(testCase: TestCase, reason: String?) {110 ignoreTest(testCase, TestResult.Ignored(reason))111 }112 private fun addChild(testCase: TestCase) {113 children.getOrPut(testCase.descriptor.parent) { mutableListOf() }.add(testCase)114 }115 override suspend fun testFinished(testCase: TestCase, result: TestResult) {116 results[testCase.descriptor] = result117 when (testCase.type) {118 TestType.Container -> {119 failTestSuiteIfError(testCase, result)120 finishTestSuite(testCase, result)121 }122 TestType.Test -> {123 if (!started.contains(testCase.descriptor)) startTest(testCase)124 if (result.isErrorOrFailure) failTest(testCase, result)125 finishTest(testCase, result)126 }127 TestType.Dynamic -> {128 if (isParent(testCase)) {129 startTestSuite(testCase)130 failTestSuiteIfError(testCase, result)131 finishTestSuite(testCase, result)132 } else {133 startTest(testCase)134 if (result.isErrorOrFailure) failTest(testCase, result)135 finishTest(testCase, result)136 }137 }138 }139 }140 private fun failTestSuiteIfError(testCase: TestCase, result: TestResult) {141 // test suites cannot be in a failed state, so we must insert a placeholder to hold any error142 when (val t = result.errorOrNull) {143 null -> Unit144 is MultipleExceptions -> t.causes.forEach { insertPlaceholder(it, testCase.descriptor) }145 else -> insertPlaceholder(t, testCase.descriptor)146 }147 }148 // returns true if this test case is a parent149 private fun isParent(testCase: TestCase) = children.getOrElse(testCase.descriptor) { mutableListOf() }.isNotEmpty()150 /**151 * For a given [TestCase] will output the "test ignored" message.152 */153 private fun ignoreTest(testCase: TestCase, result: TestResult.Ignored) {154 val msg = TeamCityMessageBuilder155 .testIgnored(prefix, formatter.format(testCase))156 .id(testCase.descriptor.path().value)157 .parent(testCase.descriptor.parent.path().value)158 .locationHint(Locations.location(testCase.source))159 .message(result.reason)160 .result(result)161 .build()162 println(msg)163 }164 /**165 * For a [TestCase] will output the "test started" message.166 */167 private fun startTest(testCase: TestCase) {168 val msg = TeamCityMessageBuilder169 .testStarted(prefix, formatter.format(testCase))170 .id(testCase.descriptor.path().value)171 .parent(testCase.descriptor.parent.path().value)172 .locationHint(Locations.location(testCase.source))173 .build()174 println(msg)175 started.add(testCase.descriptor)176 }177 /**178 * For a given [TestCase] will output the "test failed" message.179 */180 private fun failTest(testCase: TestCase, result: TestResult) {181 val msg = TeamCityMessageBuilder182 .testFailed(prefix, formatter.format(testCase))183 .id(testCase.descriptor.path().value)184 .parent(testCase.descriptor.parent.path().value)185 .duration(result.duration)186 .locationHint(Locations.location(testCase.source))187 .withException(result.errorOrNull, details)188 .result(result)189 .build()190 println(msg)191 }192 /**193 * For a given [TestCase] will output the "test finished" message.194 */195 private fun finishTest(testCase: TestCase, result: TestResult) {196 val msg = TeamCityMessageBuilder197 .testFinished(prefix, formatter.format(testCase))198 .id(testCase.descriptor.path().value)199 .parent(testCase.descriptor.parent.path().value)200 .duration(result.duration)201 .locationHint(Locations.location(testCase.source))202 .result(result)203 .build()204 println(msg)205 }206 /**207 * For a given [TestCase] will output the "test suite started" message.208 */209 private fun startTestSuite(testCase: TestCase) {210 val msg = TeamCityMessageBuilder211 .testSuiteStarted(prefix, formatter.format(testCase))212 .id(testCase.descriptor.path().value)213 .parent(testCase.descriptor.parent.path().value)214 .locationHint(Locations.location(testCase.source))215 .build()216 println(msg)217 started.add(testCase.descriptor)218 }219 /**220 * For a given [TestCase] will output the "test suite finished" message.221 */222 private fun finishTestSuite(testCase: TestCase, result: TestResult) {223 val msg = TeamCityMessageBuilder224 .testSuiteFinished(prefix, formatter.format(testCase))225 .id(testCase.descriptor.path().value)226 .parent(testCase.descriptor.parent.path().value)227 .duration(result.duration)228 .locationHint(Locations.location(testCase.source))229 .result(result)230 .build()231 println(msg)232 }233}...

Full Screen

Full Screen

TeamCityMessageBuilder.kt

Source:TeamCityMessageBuilder.kt Github

copy

Full Screen

2import io.kotest.common.errors.ComparisonError3import io.kotest.core.test.TestResult4import kotlin.time.Duration5/**6 * Creates a TeamCity message builder to be used for a single string.7 *8 * Message format:9 *10 * https://www.jetbrains.com/help/teamcity/service-messages.html11 * https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html12 * https://confluence.jetbrains.com/display/TCD65/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-servMsgsServiceMessages13 *14 * Some message implementations:15 *16 * https://github.com/JetBrains/intellij-community/blob/master/plugins/testng/testSources/com/theoryinpractice/testng/configuration/TestNGTreeHierarchyTest.java17 * https://github.com/JetBrains/intellij-community/blob/master/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestListener.java18 *19 * @param prefix Is the opening string used to signal that the line is a team city line.20 * If unspecified this defaults to the team city format '##teamcity'.21 * Can be overriden to help with testing.22 *23 * @param escapeColons team city uses colons in its format, and does not support colons inside messages properly,24 * and there is no escape, so we have to mangle colons if the output is going to the console.25 * See https://teamcity-support.jetbrains.com/hc/en-us/community/posts/206882875-Colons-in-test-service-messages-are-confusing-Team-City-26 */27class TeamCityMessageBuilder(28 prefix: String,29 messageName: String,30 private val escapeColons: Boolean = false31) {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")...

Full Screen

Full Screen

TeamCityMessageBuilderTest.kt

Source:TeamCityMessageBuilderTest.kt Github

copy

Full Screen

...3import io.kotest.engine.teamcity.TeamCityMessageBuilder4import io.kotest.matchers.shouldBe5import 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

message

Using AI Code Generation

copy

Full Screen

1import io.kotest.engine.teamcity.TeamCityMessageBuilder2fun main() {3 val message = TeamCityMessageBuilder.message("Hello World")4 println(message)5}6import io.kotest.engine.teamcity.TeamCityMessageBuilder7fun main() {8 val message = TeamCityMessageBuilder.buildProblem("Hello World")9 println(message)10}11import io.kotest.engine.teamcity.TeamCityMessageBuilder12fun main() {13 val message = TeamCityMessageBuilder.testSuiteStarted("Hello World")14 println(message)15}16import io.kotest.engine.teamcity.TeamCityMessageBuilder17fun main() {18 val message = TeamCityMessageBuilder.testSuiteFinished("Hello World")19 println(message)20}21import io.kotest.engine.teamcity.TeamCityMessageBuilder22fun main() {23 val message = TeamCityMessageBuilder.testStarted("Hello World")24 println(message)25}26import io.kotest.engine.teamcity.TeamCityMessageBuilder27fun main() {28 val message = TeamCityMessageBuilder.testFinished("Hello World")29 println(message)30}31import io.kotest.engine.teamcity.TeamCityMessageBuilder32fun main() {33 val message = TeamCityMessageBuilder.testFailed("Hello World")34 println(message)35}

Full Screen

Full Screen

message

Using AI Code Generation

copy

Full Screen

1val message = TeamCityMessageBuilder.message("message text")2message.progressStart("progress message")3message.progressFinish("progress message")4message.progressMessage("progress message")5message.testStarted("test message")6message.testFinished("test message")7message.testIgnored("test message")8message.testFailed("test message", "details")9message.testError("test message", "details")10message.testSuiteStarted("testSuite message")11message.testSuiteFinished("testSuite message")12message.buildStatus("status message")13message.buildProblem("problem message")14message.buildStatistics("statistics message")15message.buildStatistic("statistic message")16message.buildLog("log message")17message.buildLog("log message", "tag")18message.buildLog("log message", "tag", "status")19message.buildLog("log message", "tag", "status", "error")20message.buildLog("log message", "tag", "status", "error", "flowId")21message.buildLog("log message", "tag", "status", "error", "flowId", "parentFlowId")22message.buildLog("log message", "tag", "status", "error", "flowId", "parentFlowId", "block")23message.buildLog("log message", "tag", "status", "error", "flowId", "parentFlowId", "block", "timestamp")24message.buildLog("log message", "tag", "status", "error", "flowId", "parentFlowId", "block", "timestamp", "thread")25message.buildLog("log message", "tag", "status", "error", "flowId", "parentFlowId", "block", "timestamp", "thread", "testId")26message.buildLog("log message", "tag", "status", "error", "flowId", "parentFlowId", "block", "timestamp", "thread", "testId", "testName")27message.buildLog("log message", "tag", "status", "error", "flowId", "parentFlowId", "block", "timestamp", "thread", "testId", "testName", "testSuiteId")28message.buildLog("log message", "tag", "status", "error", "flowId", "parentFlowId", "block", "timestamp", "thread", "testId", "testName", "testSuiteId", "testSuiteName")

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