Best Kotest code snippet using io.kotest.engine.listener.TeamCityTestEngineListener
TeamCityTestEngineListenerTest.kt
Source:TeamCityTestEngineListenerTest.kt
...11import io.kotest.core.test.TestCase12import io.kotest.core.test.TestResult13import io.kotest.core.test.TestType14import io.kotest.core.test.config.ResolvedTestConfig15import io.kotest.engine.listener.TeamCityTestEngineListener16import io.kotest.extensions.system.captureStandardOut17import io.kotest.matchers.shouldBe18import java.io.FileNotFoundException19import kotlin.time.Duration.Companion.milliseconds20import kotlin.time.Duration.Companion.seconds21class TeamCityTestEngineListenerTest : FunSpec() {22 init {23 val a = TestCase(24 TeamCityTestEngineListenerTest::class.toDescriptor().append("a"),25 TestName("a"),26 this@TeamCityTestEngineListenerTest,27 { },28 SourceRef.ClassSource("foo.bar.Test", 12),29 TestType.Container,30 ResolvedTestConfig.default,31 null,32 null33 )34 val b = a.copy(35 parent = a,36 name = TestName("b"),37 descriptor = a.descriptor.append("b"),38 source = SourceRef.ClassSource("foo.bar.Test", 17),39 )40 val c = b.copy(41 parent = b,42 name = TestName("c"),43 descriptor = b.descriptor.append("c"),44 type = TestType.Test,45 source = SourceRef.ClassSource("foo.bar.Test", 33),46 )47 test("should support nested tests") {48 val output = captureStandardOut {49 val listener = TeamCityTestEngineListener("a")50 listener.engineStarted()51 listener.specStarted(TeamCityTestEngineListenerTest::class)52 listener.testStarted(a)53 listener.testStarted(b)54 listener.testStarted(c)55 listener.testFinished(c, TestResult.Success(123.milliseconds))56 listener.testFinished(b, TestResult.Success(324.milliseconds))57 listener.testFinished(a, TestResult.Success(653.milliseconds))58 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))59 listener.engineFinished(emptyList())60 }61 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']62a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']63a[testSuiteStarted name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' locationHint='kotest:class://foo.bar.Test:17']64a[testStarted name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' locationHint='kotest:class://foo.bar.Test:33']65a[testFinished name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='123' locationHint='kotest:class://foo.bar.Test:33' result_status='Success']66a[testSuiteFinished name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' duration='324' locationHint='kotest:class://foo.bar.Test:17' result_status='Success']67a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='653' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']68a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']69"""70 }71 test("should support errors in tests") {72 val output = captureStandardOut {73 val listener = TeamCityTestEngineListener("a", details = false)74 listener.engineStarted()75 listener.specStarted(TeamCityTestEngineListenerTest::class)76 listener.testStarted(a)77 listener.testStarted(b)78 listener.testStarted(c)79 listener.testFinished(c, TestResult.Error(653.milliseconds, Exception("boom")))80 listener.testFinished(b, TestResult.Success(123.milliseconds))81 listener.testFinished(a, TestResult.Success(324.milliseconds))82 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))83 listener.engineFinished(emptyList())84 }85 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']86a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']87a[testSuiteStarted name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' locationHint='kotest:class://foo.bar.Test:17']88a[testStarted name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' locationHint='kotest:class://foo.bar.Test:33']89a[testFailed name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='653' locationHint='kotest:class://foo.bar.Test:33' message='boom' result_status='Error']90a[testFinished name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='653' locationHint='kotest:class://foo.bar.Test:33' result_status='Error']91a[testSuiteFinished name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' duration='123' locationHint='kotest:class://foo.bar.Test:17' result_status='Success']92a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='324' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']93a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']94"""95 }96 test("should support ignored tests with reason") {97 val output = captureStandardOut {98 val listener = TeamCityTestEngineListener("a", details = false)99 listener.engineStarted()100 listener.specStarted(TeamCityTestEngineListenerTest::class)101 listener.testStarted(a)102 listener.testStarted(b)103 listener.testIgnored(c, "don't like it")104 listener.testFinished(b, TestResult.Success(123.milliseconds))105 listener.testFinished(a, TestResult.Success(324.milliseconds))106 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))107 listener.engineFinished(emptyList())108 }109 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']110a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']111a[testSuiteStarted name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' locationHint='kotest:class://foo.bar.Test:17']112a[testIgnored name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' locationHint='kotest:class://foo.bar.Test:33' message='don|'t like it' result_status='Ignored']113a[testSuiteFinished name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' duration='123' locationHint='kotest:class://foo.bar.Test:17' result_status='Success']114a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='324' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']115a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']116"""117 }118 test("should support errors in test suites by adding placeholder test") {119 val output = captureStandardOut {120 val listener = TeamCityTestEngineListener("a", details = false)121 listener.engineStarted()122 listener.specStarted(TeamCityTestEngineListenerTest::class)123 listener.testStarted(a)124 listener.testStarted(b)125 listener.testStarted(c)126 listener.testFinished(c, TestResult.Success(123.milliseconds))127 listener.testFinished(b, TestResult.Error(653.milliseconds, Exception("boom")))128 listener.testFinished(a, TestResult.Success(324.milliseconds))129 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))130 listener.engineFinished(emptyList())131 }132 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']133a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']134a[testSuiteStarted name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' locationHint='kotest:class://foo.bar.Test:17']135a[testStarted name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' locationHint='kotest:class://foo.bar.Test:33']136a[testFinished name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='123' locationHint='kotest:class://foo.bar.Test:33' result_status='Success']137a[testStarted name='Exception' id='Exception' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b']138a[testFailed name='Exception' id='Exception' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' message='boom']139a[testFinished name='Exception' id='Exception' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b']140a[testSuiteFinished name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' duration='653' locationHint='kotest:class://foo.bar.Test:17' result_status='Error']141a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='324' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']142a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']143"""144 }145 test("should support errors in specs by adding placeholder test") {146 val output = captureStandardOut {147 val listener = TeamCityTestEngineListener("a", details = false)148 listener.engineStarted()149 listener.specStarted(TeamCityTestEngineListenerTest::class)150 listener.testStarted(a)151 listener.testStarted(b)152 listener.testStarted(c)153 listener.testFinished(c, TestResult.Success(123.milliseconds))154 listener.testFinished(b, TestResult.Success(555.milliseconds))155 listener.testFinished(a, TestResult.Success(324.milliseconds))156 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Error(0.seconds, Exception("wobble")))157 listener.engineFinished(emptyList())158 }159 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']160a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']161a[testSuiteStarted name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' locationHint='kotest:class://foo.bar.Test:17']162a[testStarted name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' locationHint='kotest:class://foo.bar.Test:33']163a[testFinished name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='123' locationHint='kotest:class://foo.bar.Test:33' result_status='Success']164a[testSuiteFinished name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' duration='555' locationHint='kotest:class://foo.bar.Test:17' result_status='Success']165a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='324' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']166a[testStarted name='Exception' id='Exception' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest']167a[testFailed name='Exception' id='Exception' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' message='wobble']168a[testFinished name='Exception' id='Exception' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest']169a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']170"""171 }172 test("should support multiline error messages") {173 val output = captureStandardOut {174 val listener = TeamCityTestEngineListener("a", details = false)175 listener.engineStarted()176 listener.specStarted(TeamCityTestEngineListenerTest::class)177 listener.testStarted(a)178 listener.testStarted(b)179 listener.testStarted(c)180 listener.testFinished(181 c,182 TestResult.Error(183 123.milliseconds, FileNotFoundException(184 """185 well this is a186 big187 message"""188 )189 )190 )191 listener.testFinished(b, TestResult.Success(555.milliseconds))192 listener.testFinished(a, TestResult.Success(324.milliseconds))193 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))194 listener.engineFinished(emptyList())195 }196 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']197a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']198a[testSuiteStarted name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' locationHint='kotest:class://foo.bar.Test:17']199a[testStarted name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' locationHint='kotest:class://foo.bar.Test:33']200a[testFailed name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='123' locationHint='kotest:class://foo.bar.Test:33' message='well this is a' result_status='Error']201a[testFinished name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='123' locationHint='kotest:class://foo.bar.Test:33' result_status='Error']202a[testSuiteFinished name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' duration='555' locationHint='kotest:class://foo.bar.Test:17' result_status='Success']203a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='324' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']204a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']205"""206 }207 test("should write engine errors") {208 val output = captureStandardOut {209 val listener = TeamCityTestEngineListener("a", details = false)210 listener.engineStarted()211 listener.specStarted(TeamCityTestEngineListenerTest::class)212 listener.testStarted(a)213 listener.testStarted(b)214 listener.testStarted(c)215 listener.testFinished(c, TestResult.Success(555.milliseconds))216 listener.testFinished(b, TestResult.Success(555.milliseconds))217 listener.testFinished(a, TestResult.Success(324.milliseconds))218 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))219 listener.engineFinished(listOf(Exception("big whoop")))220 }221 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']222a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']223a[testSuiteStarted name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' locationHint='kotest:class://foo.bar.Test:17']224a[testStarted name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' locationHint='kotest:class://foo.bar.Test:33']225a[testFinished name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='555' locationHint='kotest:class://foo.bar.Test:33' result_status='Success']226a[testSuiteFinished name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' duration='555' locationHint='kotest:class://foo.bar.Test:17' result_status='Success']227a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='324' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']228a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']229a[testStarted name='Engine exception']230a[testFailed name='Engine exception' message='big whoop']231a[testFinished name='Engine exception']232"""233 }234 test("should write multiple engine errors") {235 val output = captureStandardOut {236 val listener = TeamCityTestEngineListener("a", details = false)237 listener.engineStarted()238 listener.specStarted(TeamCityTestEngineListenerTest::class)239 listener.testStarted(a)240 listener.testStarted(b)241 listener.testStarted(c)242 listener.testFinished(c, TestResult.Success(555.milliseconds))243 listener.testFinished(b, TestResult.Success(555.milliseconds))244 listener.testFinished(a, TestResult.Success(324.milliseconds))245 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))246 listener.engineFinished(listOf(Exception("big whoop"), Exception("big whoop 2")))247 }248 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']249a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']250a[testSuiteStarted name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' locationHint='kotest:class://foo.bar.Test:17']251a[testStarted name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' locationHint='kotest:class://foo.bar.Test:33']252a[testFinished name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='555' locationHint='kotest:class://foo.bar.Test:33' result_status='Success']253a[testSuiteFinished name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' duration='555' locationHint='kotest:class://foo.bar.Test:17' result_status='Success']254a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='324' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']255a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']256a[testStarted name='Engine exception 1']257a[testFailed name='Engine exception 1' message='big whoop']258a[testFinished name='Engine exception 1']259a[testStarted name='Engine exception 2']260a[testFailed name='Engine exception 2' message='big whoop 2']261a[testFinished name='Engine exception 2']262"""263 }264 test("should use comparison values with a supported exception type") {265 val output = captureStandardOut {266 val listener = TeamCityTestEngineListener("a", details = false)267 listener.engineStarted()268 listener.specStarted(TeamCityTestEngineListenerTest::class)269 listener.testStarted(a)270 listener.testStarted(b)271 listener.testStarted(c)272 listener.testFinished(273 c,274 TestResult.Error(275 555.milliseconds,276 failure(Expected(Printed("expected")), Actual(Printed("actual")))277 )278 )279 listener.testFinished(b, TestResult.Success(555.milliseconds))280 listener.testFinished(a, TestResult.Success(324.milliseconds))281 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))282 listener.engineFinished(emptyList())283 }284 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']285a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']286a[testSuiteStarted name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' locationHint='kotest:class://foo.bar.Test:17']287a[testStarted name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' locationHint='kotest:class://foo.bar.Test:33']288a[testFailed name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='555' locationHint='kotest:class://foo.bar.Test:33' message='expected:<expected> but was:<actual>' type='comparisonFailure' actual='actual' expected='expected' result_status='Error']289a[testFinished name='c' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b -- c' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' duration='555' locationHint='kotest:class://foo.bar.Test:33' result_status='Error']290a[testSuiteFinished name='b' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a -- b' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' duration='555' locationHint='kotest:class://foo.bar.Test:17' result_status='Success']291a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='324' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']292a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']293"""294 }295 test("should clear state between specs") {296 val output = captureStandardOut {297 val listener = TeamCityTestEngineListener("a", details = false)298 listener.engineStarted()299 listener.specStarted(TeamCityTestEngineListenerTest::class)300 listener.testStarted(a)301 listener.testFinished(a, TestResult.Success(124.milliseconds))302 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))303 listener.specStarted(TeamCityTestEngineListenerTest::class)304 listener.testStarted(a)305 listener.testFinished(a, TestResult.Success(523.milliseconds))306 listener.specFinished(TeamCityTestEngineListenerTest::class, TestResult.Success(0.seconds))307 listener.engineFinished(emptyList())308 }309 output shouldBe """a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']310a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']311a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='124' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']312a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']313a[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']314a[testSuiteStarted name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://foo.bar.Test:12']315a[testSuiteFinished name='a' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest/a' parent_id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' duration='523' locationHint='kotest:class://foo.bar.Test:12' result_status='Success']316a[testSuiteFinished name='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' id='com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest' locationHint='kotest:class://com.sksamuel.kotest.engine.listener.TeamCityTestEngineListenerTest:1']317"""318 }319 }320}...
TeamCityTestEngineListener.kt
Source:TeamCityTestEngineListener.kt
...17import 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 = TeamCityMessageBuilder...
TestEngineLauncher.kt
Source:TestEngineLauncher.kt
...14import io.kotest.engine.config.loadProjectConfigFromClassname15import io.kotest.engine.extensions.SpecifiedTagsTagExtension16import io.kotest.engine.listener.NoopTestEngineListener17import io.kotest.engine.listener.PinnedSpecTestEngineListener18import io.kotest.engine.listener.TeamCityTestEngineListener19import io.kotest.engine.listener.TestEngineListener20import io.kotest.engine.listener.ThreadSafeTestEngineListener21import io.kotest.mpp.log22import kotlin.reflect.KClass23/**24 * A builder class for creating and executing tests via the [TestEngine].25 *26 * Entry point for tests generated through the compiler plugins, and so the27 * public api cannot have breaking changes.28 */29class TestEngineLauncher(30 private val listener: TestEngineListener,31 private val projectConfiguration: ProjectConfiguration,32 private val configs: List<AbstractProjectConfig>,33 private val refs: List<SpecRef>,34 private val tagExpression: TagExpression?,35) {36 constructor() : this(37 NoopTestEngineListener,38 ProjectConfiguration(),39 emptyList(),40 emptyList(),41 null,42 )43 constructor(listener: TestEngineListener) : this(44 listener,45 ProjectConfiguration(),46 emptyList(),47 emptyList(),48 null,49 )50 /**51 * Convenience function to be called by the native code gen to set up the TeamCity listener.52 */53 fun withTeamCityListener(): TestEngineLauncher {54 return withListener(TeamCityTestEngineListener())55 }56 /**57 * Replace the listener with the given value.58 */59 fun withListener(listener: TestEngineListener): TestEngineLauncher {60 return TestEngineLauncher(61 listener = listener,62 projectConfiguration = projectConfiguration,63 configs = configs,64 refs = refs,65 tagExpression = tagExpression,66 )67 }68 fun withSpecs(vararg specs: Spec): TestEngineLauncher {...
TeamCityListenerIgnoredTestsEndToEndTest.kt
Source:TeamCityListenerIgnoredTestsEndToEndTest.kt
...10//import io.kotest.core.test.TestCase11//import io.kotest.core.test.TestResult12//import io.kotest.core.test.TestType13//import io.kotest.core.test.config.ResolvedTestConfig14//import io.kotest.engine.listener.TeamCityTestEngineListener15//import io.kotest.extensions.system.captureStandardOut16//import io.kotest.matchers.shouldBe17//import kotlin.reflect.KClass18//19//class TeamCityListenerIgnoredTestsEndToEndTest : FunSpec() {20//21// private val kclass: KClass<out Spec> = TeamCityListenerIgnoredTestsEndToEndTest::class22//23// private val testCase1 = TestCase(24// descriptor = kclass.toDescriptor().append("disabled test"),25// name = TestName("disabled test"),26// spec = this,27// test = { },28// source = sourceRef(),29// type = TestType.Test,30// config = ResolvedTestConfig.default.copy(enabled = { Enabled.disabled }),31// factoryId = null,32// )33//34// private val testCase2 = testCase1.copy(35// descriptor = kclass.toDescriptor().append("disabled container"),36// type = TestType.Container,37// )38//39// init {40// test("an inactive spec should have tests marked as ignored") {41// val out = captureStandardOut {42// val listener = TeamCityTestEngineListener()43// listener.specEnter(kclass)44// listener.specInactive(45// kclass,46// mapOf(47// testCase1 to TestResult.Ignored("no love"),48// testCase2 to TestResult.Ignored("rejected")49// )50// )51// listener.specExit(kclass, null)52// }53// out.trim() shouldBe54// """55//##teamcity[testSuiteStarted name='com.sksamuel.kotest.engine.listener.TeamCityListenerIgnoredTestsEndToEndTest' id='com.sksamuel.kotest.engine.listener.TeamCityListenerIgnoredTestsEndToEndTest' locationHint='kotest://com.sksamuel.kotest.engine.listener.TeamCityListenerIgnoredTestsEndToEndTest:1' test_type='spec']56//##teamcity[testIgnored name='disabled test' id='com.sksamuel.kotest.engine.listener.TeamCityListenerIgnoredTestsEndToEndTest/disabled test' parent_id='com.sksamuel.kotest.engine.listener.TeamCityListenerIgnoredTestsEndToEndTest' locationHint='kotest://com.sksamuel.kotest.engine.listener.TeamCityListenerIgnoredTestsEndToEndTest:1' test_type='test' message='no love' result_status='Ignored']...
console.kt
Source:console.kt
1package io.kotest.engine.launcher2import com.github.ajalt.mordant.TermColors3import io.kotest.common.isIntellij4import io.kotest.engine.listener.TeamCityTestEngineListener5import io.kotest.engine.listener.TestEngineListener6import io.kotest.engine.listener.EnhancedConsoleTestEngineListener7/**8 * Creates a [TestEngineListener] that will write to the console, using the provided9 * [args] to determine which output format to use.10 */11internal fun createConsoleListener(args: LauncherArgs): TestEngineListener {12 return try {13 // we support "teamcity", "taycan", "enhanced" as special values14 // taycan was the name for the fancy kotest output but has been renamed to simply enhanced15 when (args.listener) {16 "teamcity" -> TeamCityTestEngineListener()17 "taycan", "enhanced" -> EnhancedConsoleTestEngineListener(colours(args))18 null -> defaultConsoleListener()19 else -> Class.forName(args.listener).getDeclaredConstructor().newInstance() as TestEngineListener20 }21 } catch (t: Throwable) {22 println(t.message)23 t.printStackTrace()24 defaultConsoleListener()25 }26}27internal fun colours(args: LauncherArgs): TermColors {28 return when (args.termcolor) {29 "true" -> TermColors(TermColors.Level.TRUECOLOR)30 "ansi256" -> TermColors(TermColors.Level.ANSI256)31 "ansi16" -> TermColors(TermColors.Level.ANSI16)32 "auto" -> TermColors()33 else -> TermColors()34 }35}36// returns a TestEngineListener appropriate for the environment when none was specified37// If we are running from intellij, we use an IDEA compatible team city writer38// otherwise we use the default enhanced writer39internal fun defaultConsoleListener(): TestEngineListener =40 if (isIntellij()) TeamCityTestEngineListener() else EnhancedConsoleTestEngineListener(TermColors())...
TeamCityTestEngineListener
Using AI Code Generation
1import io.kotest.core.spec.style.StringSpec2import io.kotest.engine.listener.TeamCityTestEngineListener3import io.kotest.core.config.configuration4import io.kotest.core.listeners.TestEngineListener5import io.kotest.core.spec.Spec6import io.kotest.core.spec.style.StringSpec7import io.kotest.engine.listener.TeamCityTestEngineListener8import io.kotest.matchers.shouldBe9class MySpec : StringSpec({10"hello" {11}12})13class MySpec : StringSpec({14"hello" {15}16})17import io.kotest.core.spec.style.StringSpec18import io.kotest.engine.listener.TeamCityTestEngineListener19import io.kotest.core.config.configuration20import io.kotest.core.listeners.TestEngineListener21import io.kotest.core.spec.Spec22import io.kotest.core.spec.style.StringSpec23import io.kotest.engine.listener.TeamCityTestEngineListener24import io.kotest.matchers.shouldBe25class MySpec : StringSpec({26"hello" {27}28})29class MySpec : StringSpec({30"hello" {31}32})33import io.kotest.core.spec.style.StringSpec34import io.kotest.engine.listener.TeamCityTestEngineListener35import io.kotest.core.config.configuration36import io.kotest.core.listeners.TestEngineListener37import io.kotest.core.spec.Spec38import io.kotest.core.spec.style.StringSpec39import io.kotest.engine.listener.TeamCityTestEngineListener40import io.kotest.matchers.shouldBe41class MySpec : StringSpec({42"hello" {43}44})45class MySpec : StringSpec({46"hello" {47}48})49import io.kotest.core.spec.style.StringSpec50import io.kotest.engine.listener.TeamCityTestEngineListener51import io.kotest.core.config.configuration52import io.kotest.core.listeners.TestEngineListener53import io.kotest.core.spec.Spec54import io.kotest.core.spec
TeamCityTestEngineListener
Using AI Code Generation
1val listener = TeamCityTestEngineListener()2val engine = KotestEngineLauncher()3.engineListener(listener)4.suite(suite)5.execute()6val listener = TeamCityTestEngineListener()7val engine = KotestEngineLauncher()8.engineListener(listener)9.suite(suite)10.execute()
TeamCityTestEngineListener
Using AI Code Generation
1fun engineStarted(kotestEngine: KotestEngine)2fun engineFinished(kotestEngine: KotestEngine, results: TestEngineResult)3fun specStarted(kotestEngine: KotestEngine, spec: Spec)4fun specFinished(kotestEngine: KotestEngine, spec: Spec, results: TestEngineResult)5fun testStarted(kotestEngine: KotestEngine, test: TestCase)6fun testFinished(kotestEngine: KotestEngine, test: TestCase, result: TestResult)7fun testIgnored(kotestEngine: KotestEngine, test: TestCase, reason: String?)8fun testError(kotestEngine: KotestEngine, test: TestCase, t: Throwable)9fun testSkipped(kotestEngine: KotestEngine, test: TestCase, reason: String?)10fun specInstantiated(kotestEngine: KotestEngine, spec: Spec)11fun specInstantiationError(kotestEngine: KotestEngine, kclass: KClass<out Spec>, t: Throwable)12fun specInstantiationIgnored(kotestEngine: KotestEngine, kclass: KClass<out Spec>, reason: String?)13fun specScanStarted(kotestEngine: KotestEngine)14fun specScanFinished(kotestEngine: KotestEngine, results: List<SpecScanResult>)15fun specScanError(kotestEngine: KotestEngine, t: Throwable)
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!