How to use error class of io.kotest.inspectors package

Best Kotest code snippet using io.kotest.inspectors.error

MapInspectorsTest.kt

Source:MapInspectorsTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.inspectors2import io.kotest.assertions.assertSoftly3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.assertions.throwables.shouldThrowAny5import io.kotest.core.spec.style.WordSpec6import io.kotest.inspectors.forAll7import io.kotest.inspectors.forAllKeys8import io.kotest.inspectors.forAllValues9import io.kotest.inspectors.forAny10import io.kotest.inspectors.forAnyKey11import io.kotest.inspectors.forAnyValue12import io.kotest.inspectors.forAtLeastOne13import io.kotest.inspectors.forAtLeastOneKey14import io.kotest.inspectors.forAtLeastOneValue15import io.kotest.inspectors.forAtMostOne16import io.kotest.inspectors.forAtMostOneKey17import io.kotest.inspectors.forAtMostOneValue18import io.kotest.inspectors.forExactly19import io.kotest.inspectors.forKeysExactly20import io.kotest.inspectors.forNone21import io.kotest.inspectors.forNoneKey22import io.kotest.inspectors.forNoneValue23import io.kotest.inspectors.forOne24import io.kotest.inspectors.forOneKey25import io.kotest.inspectors.forOneValue26import io.kotest.inspectors.forSome27import io.kotest.inspectors.forSomeKeys28import io.kotest.inspectors.forSomeValues29import io.kotest.inspectors.forValuesExactly30import io.kotest.matchers.ints.shouldBeGreaterThan31import io.kotest.matchers.maps.shouldContain32import io.kotest.matchers.shouldBe33import io.kotest.matchers.shouldNotBe34@Suppress("ConstantConditionIf")35class MapInspectorsTest : WordSpec() {36 private val map = mapOf(1 to "1", 2 to "2", 3 to "3", 4 to "4", 5 to "5")37 init {38 "forAllKeys" should {39 "pass if all keys of a map pass" {40 map.forAllKeys {41 it.shouldBeGreaterThan(0)42 }43 }44 "return itself" {45 map.forAllKeys {46 it.shouldBeGreaterThan(0)47 }.forAllKeys {48 it.shouldBeGreaterThan(0)49 }50 }51 }52 "forAllValues" should {53 "pass if all values of a map pass" {54 map.forAllValues {55 it.toInt().shouldBeGreaterThan(0)56 }57 }58 "return itself" {59 map.forAllValues {60 it.toInt().shouldBeGreaterThan(0)61 }.forAllValues {62 it.toInt().shouldBeGreaterThan(0)63 }64 }65 }66 "forAll" should {67 "pass if all entries of a map pass" {68 map.forAll {69 it.key.shouldBe(it.value.toInt())70 }71 }72 "return itself" {73 map.forAll {74 it.key.shouldBe(it.value.toInt())75 }.forAll {76 it.key.shouldBe(it.value.toInt())77 }78 }79 "fail when an exception is thrown inside a map" {80 shouldThrowAny {81 map.forAll {82 if (true) throw NullPointerException()83 }84 }.message shouldBe "0 elements passed but expected 5\n" +85 "\n" +86 "The following elements passed:\n" +87 "--none--\n" +88 "\n" +89 "The following elements failed:\n" +90 "1=1 => java.lang.NullPointerException\n" +91 "2=2 => java.lang.NullPointerException\n" +92 "3=3 => java.lang.NullPointerException\n" +93 "4=4 => java.lang.NullPointerException\n" +94 "5=5 => java.lang.NullPointerException"95 }96 }97 "forNoneKeys" should {98 "pass if no keys pass fn test for a map" {99 map.forNoneKey {100 it.shouldBeGreaterThan(10)101 }102 }103 "return itself" {104 map.forNoneKey {105 it.shouldBeGreaterThan(10)106 }.forNoneKey {107 it.shouldBeGreaterThan(10)108 }109 }110 }111 "forNoneValues" should {112 "pass if no values pass fn test for a map" {113 map.forNoneValue {114 it.toInt().shouldBeGreaterThan(10)115 }116 }117 "return itself" {118 map.forNoneValue {119 it.toInt().shouldBeGreaterThan(10)120 }.forNoneValue {121 it.toInt().shouldBeGreaterThan(10)122 }123 }124 }125 "forNone" should {126 "pass if no entries of a map pass" {127 map.forNone {128 it shouldBe mapOf(10 to "10").entries.first()129 }130 }131 "pass if an entry throws an exception" {132 map.forNone {133 if (true) throw NullPointerException()134 }135 }136 "return itself" {137 map.forNone {138 it shouldBe mapOf(10 to "10").entries.first()139 }.forNone {140 it shouldBe mapOf(10 to "10").entries.first()141 }142 }143 "fail if one entry passes fn test" {144 shouldThrow<AssertionError> {145 map.forNone {146 it shouldBe mapOf(4 to "4").entries.first()147 }148 }.message shouldBe """1 elements passed but expected 0149The following elements passed:1504=4151The following elements failed:1521=1 => expected:<4=4> but was:<1=1>1532=2 => expected:<4=4> but was:<2=2>1543=3 => expected:<4=4> but was:<3=3>1555=5 => expected:<4=4> but was:<5=5>"""156 }157 "fail if all entries pass fn test" {158 shouldThrow<AssertionError> {159 map.forNone {160 it.key shouldBe it.value.toInt()161 }162 }.message shouldBe """5 elements passed but expected 0163The following elements passed:1641=11652=21663=31674=41685=5169The following elements failed:170--none--"""171 }172 "work inside assertSoftly block (for map)" {173 assertSoftly(map) {174 forNone {175 it.key shouldBe 10176 it.value shouldBe "10"177 }178 }179 }180 }181 "forSomeKeys" should {182 "pass if one key pass fn test for a map" {183 map.forSomeKeys {184 it shouldBe 1185 }186 }187 "return itself" {188 map.forSomeKeys {189 it shouldBe 1190 }.forSomeKeys {191 it shouldBe 1192 }193 }194 }195 "forSomeValues" should {196 "pass if one value pass fn test for a map" {197 map.forSomeValues {198 it.toInt() shouldBe 1199 }200 }201 "return itself" {202 map.forSomeValues {203 it.toInt() shouldBe 1204 }.forSomeValues {205 it.toInt() shouldBe 1206 }207 }208 }209 "forSome" should {210 "pass if one entry pass test" {211 map.forSome {212 it shouldBe mapOf(1 to "1").entries.first()213 }214 }215 "return itself" {216 map.forSome {217 it shouldBe mapOf(1 to "1").entries.first()218 }.forSome {219 it shouldBe mapOf(1 to "1").entries.first()220 }221 }222 "fail if no entries pass test" {223 shouldThrow<AssertionError> {224 map.forSome {225 it shouldBe mapOf(0 to "0").entries.first()226 }227 }.message shouldBe """No elements passed but expected at least one228The following elements passed:229--none--230The following elements failed:2311=1 => expected:<0=0> but was:<1=1>2322=2 => expected:<0=0> but was:<2=2>2333=3 => expected:<0=0> but was:<3=3>2344=4 => expected:<0=0> but was:<4=4>2355=5 => expected:<0=0> but was:<5=5>"""236 }237 "fail if all entries pass test" {238 shouldThrow<AssertionError> {239 map.forSome {240 it.key shouldBe it.value.toInt()241 }242 }.message shouldBe """All elements passed but expected < 5243The following elements passed:2441=12452=22463=32474=42485=5249The following elements failed:250--none--"""251 }252 "work inside assertSoftly block (for map)" {253 assertSoftly(map) {254 forSome {255 it.key shouldBe 1256 it.value shouldBe "1"257 }258 }259 }260 }261 "forOneKey" should {262 "pass if one key pass fn test for a map" {263 map.forOneKey {264 it shouldBe 1265 }266 }267 "return itself" {268 map.forOneKey {269 it shouldBe 1270 }.forOneKey {271 it shouldBe 1272 }273 }274 }275 "forOneValue" should {276 "pass if one value pass fn test for a map" {277 map.forOneValue {278 it.toInt() shouldBe 1279 }280 }281 "return itself" {282 map.forOneValue {283 it.toInt() shouldBe 1284 }.forOneValue {285 it.toInt() shouldBe 1286 }287 }288 }289 "forOne" should {290 "pass if one entry pass test" {291 map.forOne {292 it shouldBe mapOf(1 to "1").entries.first()293 }294 }295 "return itself" {296 map.forOne {297 it shouldBe mapOf(1 to "1").entries.first()298 }.forOne {299 it shouldBe mapOf(1 to "1").entries.first()300 }301 }302 "fail if > 1 entries pass test" {303 shouldThrow<AssertionError> {304 map.forOne {305 mapOf(3 to "3", 4 to "4", 5 to "5").shouldContain(it.toPair())306 }307 }.message shouldBe """3 elements passed but expected 1308The following elements passed:3093=33104=43115=5312The following elements failed:3131=1 => Map should contain mapping 1=1 but was {3=3, 4=4, 5=5}3142=2 => Map should contain mapping 2=2 but was {3=3, 4=4, 5=5}"""315 }316 "fail if no entries pass test" {317 shouldThrow<AssertionError> {318 map.forOne {319 it shouldBe mapOf(22 to "22").entries.first()320 }321 }.message shouldBe """0 elements passed but expected 1322The following elements passed:323--none--324The following elements failed:3251=1 => expected:<22=22> but was:<1=1>3262=2 => expected:<22=22> but was:<2=2>3273=3 => expected:<22=22> but was:<3=3>3284=4 => expected:<22=22> but was:<4=4>3295=5 => expected:<22=22> but was:<5=5>"""330 }331 "work inside assertSoftly block (for map)" {332 assertSoftly(map) {333 forOne {334 it.key shouldBe 1335 it.value shouldBe "1"336 }337 }338 }339 }340 "forAnyKey" should {341 "pass if one key pass fn test for a map" {342 map.forAnyKey {343 it shouldBe 1344 }345 }346 "return itself" {347 map.forAnyKey {348 it shouldBe 1349 }.forAnyKey {350 it shouldBe 1351 }352 }353 }354 "forAnyValue" should {355 "pass if one value pass fn test for a map" {356 map.forAnyValue {357 it.toInt() shouldBe 1358 }359 }360 "return itself" {361 map.forAnyValue {362 it.toInt() shouldBe 1363 }.forAnyValue {364 it.toInt() shouldBe 1365 }366 }367 }368 "forAny" should {369 "pass if any entries pass test" {370 map.forAny {371 mapOf(1 to "1", 2 to "2").shouldContain(it.toPair())372 }373 }374 "return itself" {375 map.forAny {376 mapOf(1 to "1", 2 to "2").shouldContain(it.toPair())377 }.forAny {378 mapOf(1 to "1", 2 to "2").shouldContain(it.toPair())379 }380 }381 "fail if no entries pass test" {382 shouldThrow<AssertionError> {383 map.forAny {384 it shouldBe mapOf(6 to "6").entries.first()385 }386 }.message shouldBe """0 elements passed but expected at least 1387The following elements passed:388--none--389The following elements failed:3901=1 => expected:<6=6> but was:<1=1>3912=2 => expected:<6=6> but was:<2=2>3923=3 => expected:<6=6> but was:<3=3>3934=4 => expected:<6=6> but was:<4=4>3945=5 => expected:<6=6> but was:<5=5>"""395 }396 "work inside assertSoftly block (for map)" {397 assertSoftly(map) {398 forAny {399 it.key shouldBe 1400 it.value shouldBe "1"401 }402 }403 }404 }405 "forKeysExactly" should {406 "pass if one key pass fn test for a map" {407 map.forKeysExactly(1) {408 it shouldBe 1409 }410 }411 "return itself" {412 map.forKeysExactly(1) {413 it shouldBe 1414 }.forKeysExactly(1) {415 it shouldBe 1416 }417 }418 }419 "forValuesExactly" should {420 "pass if one value pass fn test for a map" {421 map.forValuesExactly(1) {422 it.toInt() shouldBe 1423 }424 }425 "return itself" {426 map.forValuesExactly(1) {427 it.toInt() shouldBe 1428 }.forValuesExactly(1) {429 it.toInt() shouldBe 1430 }431 }432 }433 "forExactly" should {434 "pass if exactly k entries pass" {435 map.forExactly(4) {436 it shouldNotBe mapOf(1 to "1").entries.first()437 }438 }439 "fail if more entries pass test" {440 shouldThrow<AssertionError> {441 map.forExactly(3) {442 it shouldNotBe mapOf(1 to "1").entries.first()443 }444 }.message shouldBe """4 elements passed but expected 3445The following elements passed:4462=24473=34484=44495=5450The following elements failed:4511=1 => 1=1 should not equal 1=1"""452 }453 "fail if less entries pass test" {454 shouldThrow<AssertionError> {455 map.forExactly(5) {456 it shouldNotBe mapOf(1 to "1").entries.first()457 }458 }.message shouldBe """4 elements passed but expected 5459The following elements passed:4602=24613=34624=44635=5464The following elements failed:4651=1 => 1=1 should not equal 1=1"""466 }467 "fail if no entries pass test" {468 shouldThrow<AssertionError> {469 map.forExactly(1) {470 it shouldBe mapOf(10 to "10").entries.first()471 }472 }.message shouldBe """0 elements passed but expected 1473The following elements passed:474--none--475The following elements failed:4761=1 => expected:<10=10> but was:<1=1>4772=2 => expected:<10=10> but was:<2=2>4783=3 => expected:<10=10> but was:<3=3>4794=4 => expected:<10=10> but was:<4=4>4805=5 => expected:<10=10> but was:<5=5>"""481 }482 }483 "forAtMostOneKey" should {484 "pass if one key pass fn test for a map" {485 map.forAtMostOneKey {486 it shouldBe 1487 }488 }489 "return itself" {490 map.forAtMostOneKey {491 it shouldBe 1492 }.forAtMostOneKey {493 it shouldBe 1494 }495 }496 }497 "forAtMostOneValue" should {498 "pass if one value pass fn test for a map" {499 map.forAtMostOneValue {500 it.toInt() shouldBe 1501 }502 }503 "return itself" {504 map.forAtMostOneValue {505 it.toInt() shouldBe 1506 }.forAtMostOneValue {507 it.toInt() shouldBe 1508 }509 }510 }511 "forAtMostOne" should {512 "pass if one elements pass test" {513 map.forAtMostOne {514 it shouldBe mapOf(3 to "3")515 }516 }517 "fail if 2 elements pass test" {518 shouldThrow<AssertionError> {519 map.forAtMostOne {520 mapOf(4 to "4", 5 to "5").shouldContain(it.toPair())521 }522 }.message shouldBe """2 elements passed but expected at most 1523The following elements passed:5244=45255=5526The following elements failed:5271=1 => Map should contain mapping 1=1 but was {4=4, 5=5}5282=2 => Map should contain mapping 2=2 but was {4=4, 5=5}5293=3 => Map should contain mapping 3=3 but was {4=4, 5=5}"""530 }531 "work inside assertSoftly block (for map)" {532 assertSoftly(map) {533 forAtMostOne {534 it.key shouldBe 1535 it.value shouldBe "1"536 }537 }538 }539 }540 "forAtLeastOneKey" should {541 "pass if one key pass fn test for a map" {542 map.forAtLeastOneKey {543 it shouldBe 1544 }545 }546 "return itself" {547 map.forAtLeastOneKey {548 it shouldBe 1549 }.forAtLeastOneKey {550 it shouldBe 1551 }552 }553 }554 "forAtLeastOneValue" should {555 "pass if one value pass fn test for a map" {556 map.forAtLeastOneValue {557 it.toInt() shouldBe 1558 }559 }560 "return itself" {561 map.forAtLeastOneValue {562 it.toInt() shouldBe 1563 }.forAtLeastOneValue {564 it.toInt() shouldBe 1565 }566 }567 }568 "forAtLeastOne" should {569 "pass if one elements pass test" {570 map.forAtLeastOne {571 it shouldBe mapOf(3 to "3").entries.first()572 }573 }574 "fail if no elements pass test" {575 shouldThrow<AssertionError> {576 map.forAtLeastOne {577 it shouldBe mapOf(22 to "22").entries.first()578 }579 }.message shouldBe """0 elements passed but expected at least 1580The following elements passed:581--none--582The following elements failed:5831=1 => expected:<22=22> but was:<1=1>5842=2 => expected:<22=22> but was:<2=2>5853=3 => expected:<22=22> but was:<3=3>5864=4 => expected:<22=22> but was:<4=4>5875=5 => expected:<22=22> but was:<5=5>"""588 }589 "work inside assertSoftly block (for map)" {590 assertSoftly(map) {591 forAtLeastOne {592 it.key shouldBe 1593 it.value shouldBe "1"594 }595 }596 }597 }598 }599}...

Full Screen

Full Screen

AnalyseMessagesTest.kt

Source:AnalyseMessagesTest.kt Github

copy

Full Screen

...13class AnalyseMessagesTest : FreeSpec({14 "analyseMessages() returns results which" - {15 "given a single passing scenario" - {16 val result = openMessageSample("singlePassingScenario").use { analyseMessages(it) }17 "contains no errors" {18 result.problemCount shouldBe 019 }20 }21 "given a single failing scenario" - {22 val result = openMessageSample("singleFailingScenario").use { analyseMessages(it) }23// result.appendTo(System.out)24 "contains a single error" {25 result.problemCount shouldBe 126 result.features shouldHaveSize 127 result.features[0].scenarios shouldHaveSize 128 }29 val feature = result.features[0]30 "references the correct feature" {31 feature.feature.name shouldBe "failing"32 }33 val error = feature.scenarios[0]34 "references the correct scenario" {35 error.scenario.name shouldBe "failing"36 }37 "references the correct step" {38 val step = error.step39 step should beInstanceOf(StepInfo::class)40 if(step is StepInfo) {41 step.text shouldBe "it fails"42 }43 }44 "has the correct status" {45 error.status shouldBe FAILED46 }47 }48 "given a single unimplemented scenario" - {49 val result = openMessageSample("singleUnimplementedScenario").use { analyseMessages(it) }50// result.appendTo(System.out)51 "contains a single error" {52 result.problemCount shouldBe 153 result.features shouldHaveSize 154 result.features[0].scenarios shouldHaveSize 155 }56 "has the correct status" {57 result.features[0].scenarios[0].status shouldBe UNDEFINED58 }59 }60 "given multiple features & scenarios" - {61 val result = openMessageSample("1Failing1Passing1Unimplemented").use { analyseMessages(it) }62// result.appendTo(System.out)63 "contains the correct number of error" {64 result.problemCount shouldBe 265 }66 "references the correct number of features" {67 result.features shouldHaveSize 268 }69 "associates errors with the correct features and scenarios" {70 result.features.forAll {71 it.scenarios shouldHaveSize 172 }73 result.features.forOne {74 it.feature.name shouldBe "failing"75 val s = it.scenarios[0]76 s.scenario.name shouldBe "failing"77 s.status shouldBe FAILED78 }79 result.features.forOne {80 it.feature.name shouldBe "unimplemented"81 val s = it.scenarios[0]82 s.scenario.name shouldBe "unimplemented"83 s.status shouldBe UNDEFINED84 }85 }86 }87 "given a feature containing rules" - {88 val result = openMessageSample("2RulesWith1ErrorInEach").use { analyseMessages(it) }89// result.appendTo(System.out)90 "contains the correct number of errors" {91 result.problemCount shouldBe 292 result.features shouldHaveSize 193 }94 val feature = result.features[0]95 "references the correct number of rules" {96 feature.allChildren shouldHaveSize 297 feature.rules shouldHaveSize 298 feature.scenarios should beEmpty()99 }100 "associates errors with the correct rules and scenarios" {101 feature.rules.forAll {102 it.scenarios shouldHaveSize 1103 }104 feature.rules.forOne {105 it.rule.name shouldBe "Rules should be included"106 val s = it.scenarios[0]107 s.scenario.name shouldBe "This should fail"108 s.status shouldBe FAILED109 }110 feature.rules.forOne {111 it.rule.name shouldBe "Multiple rules are allowed"112 val s = it.scenarios[0]113 s.scenario.name shouldBe "This is unimplemented"114 s.status shouldBe UNDEFINED115 }116 }117 }118 "given rules with background steps" - {119 val result = openMessageSample("2RulesWithBackground").use { analyseMessages(it) }120// result.appendTo(System.out)121 "contains the correct number of errors" {122 result.problemCount shouldBe 2123 result.features shouldHaveSize 1124 }125 val feature = result.features[0]126 "references the correct number of rules" {127 feature.allChildren shouldHaveSize 2128 feature.rules shouldHaveSize 2129 feature.scenarios should beEmpty()130 }131 "references the background when a background step fails" {132 feature.rules.forOne {133 it.rule.name shouldBe("backstories can fail")134 val s = it.scenarios[0]135 s.scenario.name shouldBe "pre-failure"136 val step = s.step137 step should beInstanceOf(BackgroundStepInfo::class)138 if(step is BackgroundStepInfo) {139 step.background.name shouldBe "bad backstory"140 }141 }142 }143 "references the scenario when a scenario step fails" {144 feature.rules.forOne {145 it.rule.name shouldBe("backstories can succeed")146 val s = it.scenarios[0]147 s.scenario.name shouldBe "failure"148 val step = s.step149 step.type shouldBe TestCaseStepType.STEP150 }151 }152 }153 "given a scenario with step variables" - {154 val result = openMessageSample("1ScenarioWithVariables").use { analyseMessages(it) }155// result.appendTo(System.out)156 "contains a single error" {157 result.problemCount shouldBe 1158 result.features shouldHaveSize 1159 result.features[0].scenarios shouldHaveSize 1160 }161 val error = result.features[0].scenarios[0]162 "references the correct step" {163 (error.step as StepInfo).text shouldBe "3 equals 4"164 }165 "has the correct status" {166 error.status shouldBe FAILED167 }168 }169 "given a scenario outline" - {170 val result = openMessageSample("scenarioOutlineWith3Examples").use { analyseMessages(it) }171// result.appendTo(System.out)172 "contains the correct number of errors error" {173 result.problemCount shouldBe 2174 result.features shouldHaveSize 1175 result.features[0].scenarios shouldHaveSize 2176 }177 "contains the expected errors" {178 result.features[0].scenarios.forOne {179 it.scenario.name shouldBe "Outline var"180 (it.step as StepInfo).text shouldBe "3 equals 4"181 }182 result.features[0].scenarios.forOne {183 it.scenario.name shouldBe "Outline baz"184 (it.step as StepInfo).text shouldBe "123 equals 3231"185 }186 }187 }188 "given a scenario containing a data table" - {189 val result = openMessageSample("scenarioWithDataTable").use { analyseMessages(it) }190// result.appendTo(System.out)191 "contains a single error" {192 result.problemCount shouldBe 1193 }194 "references the correct step" {195 (result.features[0].scenarios[0].step as StepInfo).text shouldBe "this table fails:"196 }197 }198 "given a scenario with a failing hook" - {199 val result = openMessageSample("scenarioWithFailingHook").use { analyseMessages(it) }200// result.appendTo(System.out)201 "contains a single error" {202 result.problemCount shouldBe 1203 }204 "references the failing hook" {205 val scenario = result.features[0].scenarios[0]206 scenario.scenario.name shouldBe "Hook"207 scenario.step.type shouldBe TestCaseStepType.HOOK208 }209 }210 }211})...

Full Screen

Full Screen

NewlineBeforeElseTest.kt

Source:NewlineBeforeElseTest.kt Github

copy

Full Screen

1package nl.deltadak.ktlintruleset2import com.pinterest.ktlint.core.LintError3import com.pinterest.ktlint.test.format4import com.pinterest.ktlint.test.lint5import io.kotest.core.spec.style.StringSpec6import io.kotest.inspectors.forExactly7import io.kotest.matchers.collections.shouldBeEmpty8import io.kotest.matchers.shouldBe9class NewlineBeforeElseTest : StringSpec() {10 init {11 "no newline before else" {12 val lintErrors = NewlineBeforeKeywordRule().lint("""13 val temp = if (true) {14 "hi"15 } else {16 "nothing"17 }18 """.trimIndent())19 lintErrors.forExactly(1) {20 it.shouldBe(LintError(3, 3, NewlineBeforeKeywordRule().id, "Missing newline before \"else\""))21 }22 }23 "curly brace before else" {24 val lintErrors = NewlineBeforeKeywordRule().lint("""25 val temp = if (true) {26 "hi"27 }else {28 "nothing"29 }30 """.trimIndent())31 lintErrors.forExactly(1) {32 it.shouldBe(LintError(3, 2, NewlineBeforeKeywordRule().id, "Missing newline before \"else\""))33 }34 }35 "newline before else" {36 val lintErrors = NewlineBeforeKeywordRule().lint("""37 val temp = if (true) {38 "hi"39 }40 else {41 "nothing"42 }43 """.trimIndent())44 lintErrors.shouldBeEmpty()45 }46 "newline between comment and else" {47 val lintErrors = NewlineBeforeKeywordRule().lint("""48 val temp = if (true) {49 "hi"50 }51 // This is a comment.52 else {53 "nothing"54 }55 """.trimIndent())56 lintErrors.shouldBeEmpty()57 }58 "expected no newline before else" {59 val lintErrors = NewlineBeforeKeywordRule().lint("""60 val temp = if (true) "hi" else "nothing"61 """.trimIndent())62 lintErrors.shouldBeEmpty()63 }64 "formatting" {65 NewlineBeforeKeywordRule().format("""66 class Dummy {67 fun temp() {68 if (true) {69 "hi"70 } else {71 "nothing"72 }73 }74 }75 """.trimIndent()) shouldBe """76 class Dummy {77 fun temp() {78 if (true) {79 "hi"80 }81 else {82 "nothing"83 }84 }85 }86 """.trimIndent()87 }88 }89}...

Full Screen

Full Screen

SpacesAroundKeywordTest.kt

Source:SpacesAroundKeywordTest.kt Github

copy

Full Screen

1package nl.deltadak.ktlintruleset2import com.pinterest.ktlint.core.LintError3import com.pinterest.ktlint.test.format4import com.pinterest.ktlint.test.lint5import io.kotest.core.spec.style.StringSpec6import io.kotest.inspectors.forExactly7import io.kotest.matchers.collections.shouldBeEmpty8import io.kotest.matchers.shouldBe9class SpacesAroundKeywordTest : StringSpec() {10 init {11 "space after if" {12 val lintErrors = SpacesAroundKeywordRule().lint("""13 fun temp() {14 if (true) println(true)15 }16 """.trimIndent())17 lintErrors.shouldBeEmpty()18 }19 "no space after if" {20 val lintErrors = SpacesAroundKeywordRule().lint("""21 fun temp() {22 if(true) println(true)23 }24 """.trimIndent())25 lintErrors.forExactly(1) {26 it.shouldBe(LintError(2, 7, "keyword-spaces", "Missing space after \"if\""))27 }28 }29 "formatting if" {30 SpacesAroundKeywordRule().format("""31 fun temp() {32 if(true) println(true)33 }34 """.trimIndent()) shouldBe """35 fun temp() {36 if (true) println(true)37 }38 """.trimIndent()39 }40 "no space after get" {41 val lintErrors = SpacesAroundKeywordRule().lint("""42 class Dummy {43 val dum: Int44 get() = 345 }46 """.trimIndent())47 lintErrors.shouldBeEmpty()48 }49 "space after get" {50 val lintErrors = SpacesAroundKeywordRule().lint("""51 class Dummy {52 val dum: Int53 get () = 354 }55 """.trimIndent())56 lintErrors.forExactly(1) {57 it.shouldBe(LintError(3, 9, "keyword-spaces", "Unexpected space after \"get\""))58 }59 }60 "formatting get" {61 SpacesAroundKeywordRule().format("""62 class Dummy {63 val dum: Int64 get () = 365 }66 """.trimIndent()) shouldBe """67 class Dummy {68 val dum: Int69 get() = 370 }71 """.trimIndent()72 }73 }74}...

Full Screen

Full Screen

NewlineAfterClassHeaderTest.kt

Source:NewlineAfterClassHeaderTest.kt Github

copy

Full Screen

1package nl.deltadak.ktlintruleset2import com.pinterest.ktlint.core.LintError3import com.pinterest.ktlint.test.format4import com.pinterest.ktlint.test.lint5import io.kotest.core.spec.style.StringSpec6import io.kotest.inspectors.forExactly7import io.kotest.matchers.collections.shouldBeEmpty8import io.kotest.matchers.shouldBe9class NewlineAfterClassHeaderTest : StringSpec() {10 init {11 "no newline after class header" {12 val lintErrors = NewlineAfterClassHeader().lint("""13 class Hi {14 override fun toString() = "bye"15 }16 """.trimIndent())17 lintErrors.forExactly(1) {18 it.shouldBe(LintError(1, 10, NewlineAfterClassHeader().id, "Missing newline after class header"))19 }20 }21 "no newline at start of companion object" {22 val lintErrors = NewlineAfterClassHeader().lint("""23 class Hi {24 25 companion object {26 const val WHAT = "bye"27 }28 }29 """.trimIndent())30 lintErrors.forExactly(1) {31 it.shouldBe(LintError(3, 22, NewlineAfterClassHeader().id, "Missing newline after class header"))32 }33 }34 "with newline" {35 val lintErrors = NewlineAfterClassHeader().lint("""36 class Hi {37 38 companion object {39 40 const val WHAT = "bye"41 }42 }43 """.trimIndent())44 lintErrors.shouldBeEmpty()45 }46 "formatting" {47 NewlineAfterClassHeader().format("""48 class Hi {49 companion object {50 const val WHAT = "bye"51 }52 }53 """.trimIndent()) shouldBe """54 class Hi {55 56 companion object {57 58 const val WHAT = "bye"59 }60 }61 """.trimIndent()62 }63 }64}...

Full Screen

Full Screen

ClienteServiceTest.kt

Source:ClienteServiceTest.kt Github

copy

Full Screen

1package service2import br.com.iupp.controller.dto.ClientRequest3import br.com.iupp.controller.dto.ClientResponse4import br.com.iupp.model.ClientEntity5import br.com.iupp.repository.ClientRepository6import br.com.iupp.repository.ClientRepositoryImpl7import br.com.iupp.service.ClientService8import br.com.iupp.service.ClientServiceImpl9import io.kotest.core.spec.style.AnnotationSpec10import io.kotest.inspectors.buildAssertionError11import io.kotest.matchers.shouldBe12import io.micronaut.test.extensions.kotest.annotation.MicronautTest13import io.mockk.every14import io.mockk.mockk15import java.util.*16@MicronautTest17class ClienteServiceTest:AnnotationSpec() {18 val repository = mockk<ClientRepository>(relaxed = true)19 val service = ClientServiceImpl(repository)20 lateinit var clientEntity: ClientEntity21 lateinit var clientRequest: ClientRequest22 lateinit var clientResponse: ClientResponse23 val id = UUID.randomUUID()24 @BeforeEach25 fun setUp(){26 clientEntity = ClientEntity(id = id,name = "bia", email = "bia@gmail.com", cpf = "12345678900")27 clientRequest = ClientRequest("bia","bia@gmail.com","12345678900")28 clientResponse = ClientResponse(id = id, name = "bia", email = "bia@gmail.com")29 }30 @Test31 fun `send a client request and should be received a client response`(){32 every { repository.repSaveClient(any()) } answers { clientEntity }33 val result = service.saveClient(clientRequest)34 result shouldBe clientResponse35 }36 @Test37 fun `should be received a list of clientResponse`(){38 every { repository.ListOfClient() } answers { listOf(clientResponse) }39 val result = service.listClient()40 result shouldBe listOf(clientResponse)41 }42 @Test43 fun `should be received a clientResponse`(){44 every { repository.findClienteById(any())} answers { clientResponse }45 val result = service.findClientebyId(id)46 result shouldBe clientResponse47 }48}...

Full Screen

Full Screen

error.kt

Source:error.kt Github

copy

Full Screen

...6import io.kotest.inspectors.ElementFail7import io.kotest.inspectors.ElementPass8import io.kotest.inspectors.ElementResult9/**10 * Build assertion error message.11 *12 * Show 10 passed and failed results by default. You can change the number of output results by setting the13 * system property `kotest.assertions.output.max=20`.14 *15 * E.g.:16 *17 * ```18 * -Dkotest.assertions.output.max=2019 * ```20 */21fun <T> buildAssertionError(msg: String, results: List<ElementResult<T>>): Nothing {22 val maxResults = AssertionsConfig.maxErrorsOutput23 val passed = results.filterIsInstance<ElementPass<T>>()24 val failed = results.filterIsInstance<ElementFail<T>>()...

Full Screen

Full Screen

AppKtTest.kt

Source:AppKtTest.kt Github

copy

Full Screen

...23 // then24 String(out.toByteArray()) shouldBe expectedOutput25 }26 }27 "should display error information"{28 listOf(29 "1 2 3 4 X command" to "ERROR: Provided value: 'X' at index:5 is not recognizable by any known parser\n",30 ).forAll { (line, expectedOutput) ->31 // given32 val out = ByteArrayOutputStream()33 val app = App(PrintStream(out))34 // when35 app.printSummary(line)36 // then37 String(out.toByteArray()) shouldBe expectedOutput38 }39 }40})...

Full Screen

Full Screen

error

Using AI Code Generation

copy

Full Screen

1val result = listOf(1, 2, 3, 4, 5)2result.forAll {3it should beLessThan(6)4}5val result = listOf(1, 2, 3, 4, 5)6result.forAll {7it should beLessThan(6)8}9at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:39)10at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:36)11at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:33)12at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:30)13at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:27)14at io.kotest.inspectors.InspectorError$Companion.create$default(InspectorError.kt:26)15at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:25)16at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:24)17at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:23)18at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:22)19at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:21)20at io.kotest.inspectors.InspectorError$Companion.create$default(InspectorError.kt:20)21at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:19)22at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:18)23at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:17)24at io.kotest.inspectors.InspectorError$Companion.create(InspectorError.kt:16)

Full Screen

Full Screen

error

Using AI Code Generation

copy

Full Screen

1 import io.kotest.inspectors.forAll2 import io.kotest.matchers.shouldBe3 import org.junit.jupiter.api.Test4 class ErrorClassTest {5 fun `should use error class`() {6 val list = listOf("a", "b", "c")7 forAll(list) { it.length shouldBe 1 }8 }9 }

Full Screen

Full Screen

error

Using AI Code Generation

copy

Full Screen

1 context("Should be able to use error class of io.kotest.inspectors package") {2 val list = listOf(1, 2, 3, 4)3 shouldThrowExactly<IllegalArgumentException> {4 list.forEach {5 if (it == 3) {6 throw IllegalArgumentException("3 is not allowed")7 }8 }9 }10 }11 }12}

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.

Most used methods in error

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful