How to use test method of io.kotest.matchers.collections.sorted class

Best Kotest code snippet using io.kotest.matchers.collections.sorted.test

RandomServiceTest.kt

Source:RandomServiceTest.kt Github

copy

Full Screen

1package io.github.serpro69.kfaker2import io.kotest.assertions.assertSoftly3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.DescribeSpec5import io.kotest.matchers.collections.shouldBeIn6import io.kotest.matchers.collections.shouldBeSortedWith7import io.kotest.matchers.collections.shouldContain8import io.kotest.matchers.collections.shouldContainAll9import io.kotest.matchers.collections.shouldHaveSize10import io.kotest.matchers.collections.shouldNotBeSortedWith11import io.kotest.matchers.should12import io.kotest.matchers.shouldBe13import io.kotest.matchers.shouldNotBe14import io.kotest.matchers.types.beInstanceOf15import java.util.*16internal class RandomServiceTest : DescribeSpec({17 describe("RandomService instance") {18 val config = fakerConfig { random = Random() }19 val randomService = RandomService(config)20 context("nextInt(bound) fun") {21 val values = List(100) { randomService.nextInt(10) }22 it("return value should be within specified range") {23 values.all { it < 10 } shouldBe true24 }25 }26 context("nextInt(min, max) fun") {27 val values = List(100) { randomService.nextInt(6..8) }28 it("return value should be within specified range") {...

Full Screen

Full Screen

TestSchedule.kt

Source:TestSchedule.kt Github

copy

Full Screen

...7import edu.illinois.cs.cs125.cisapi.ScheduleYearSemester8import edu.illinois.cs.cs125.cisapi.ScheduleYearSemesterDepartment9import edu.illinois.cs.cs125.cisapi.Section10import edu.illinois.cs.cs125.cisapi.fromXml11import io.kotest.core.spec.style.StringSpec12import io.kotest.matchers.collections.shouldContainInOrder13import io.kotest.matchers.collections.shouldHaveAtLeastSize14import io.kotest.matchers.collections.shouldHaveSize15import io.kotest.matchers.ints.shouldBeGreaterThan16import io.kotest.matchers.shouldBe17import io.kotest.matchers.shouldNotBe18import io.kotest.matchers.string.shouldEndWith19import io.kotest.matchers.string.shouldStartWith20import java.io.File21private fun String.load() = TestSchedule::class.java.getResource("/$this").readText()22@Suppress("BlockingMethodInNonBlockingContext")23class TestSchedule : StringSpec({24 "should load local schedule.xml properly" {25 "schedule.xml".load().fromXml<Schedule>().also { schedule ->26 schedule.calendarYears shouldHaveSize 1727 schedule.calendarYears.map { year -> year.id }.sorted() shouldContainInOrder (2004..2020).toList()28 schedule.calendarYears.forEach {29 it.href.toString() shouldEndWith "${it.year}.xml"30 }31 }32 }33 "should load remote schedule.xml properly" {...

Full Screen

Full Screen

FailingKotestAsserts.kt

Source:FailingKotestAsserts.kt Github

copy

Full Screen

1package testing.failing2import arrow.core.*3import io.kotest.assertions.arrow.either.shouldBeLeft4import io.kotest.assertions.arrow.either.shouldBeRight5import io.kotest.assertions.arrow.nel.shouldContain6import io.kotest.assertions.arrow.nel.shouldContainNull7import io.kotest.assertions.arrow.option.shouldBeNone8import io.kotest.assertions.arrow.option.shouldBeSome9import io.kotest.assertions.arrow.validation.shouldBeInvalid10import io.kotest.assertions.arrow.validation.shouldBeValid11import io.kotest.assertions.asClue12import io.kotest.assertions.assertSoftly13import io.kotest.assertions.json.*14import io.kotest.assertions.throwables.shouldThrowAny15import io.kotest.assertions.throwables.shouldThrowExactly16import io.kotest.assertions.withClue17import io.kotest.matchers.Matcher18import io.kotest.matchers.MatcherResult19import io.kotest.matchers.booleans.shouldBeFalse20import io.kotest.matchers.booleans.shouldBeTrue21import io.kotest.matchers.collections.shouldBeEmpty22import io.kotest.matchers.collections.shouldBeOneOf23import io.kotest.matchers.collections.shouldBeSameSizeAs24import io.kotest.matchers.collections.shouldBeSorted25import io.kotest.matchers.collections.shouldContain26import io.kotest.matchers.date.shouldBeAfter27import io.kotest.matchers.ints.shouldBeEven28import io.kotest.matchers.ints.shouldBeGreaterThan29import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual30import io.kotest.matchers.ints.shouldBeLessThan31import io.kotest.matchers.ints.shouldBeLessThanOrEqual32import io.kotest.matchers.ints.shouldBeZero33import io.kotest.matchers.maps.shouldBeEmpty34import io.kotest.matchers.maps.shouldContain35import io.kotest.matchers.maps.shouldContainKey36import io.kotest.matchers.maps.shouldContainValue37import io.kotest.matchers.nulls.shouldBeNull38import io.kotest.matchers.should39import io.kotest.matchers.shouldBe40import io.kotest.matchers.shouldNot41import io.kotest.matchers.string.shouldBeBlank42import io.kotest.matchers.string.shouldBeEmpty43import io.kotest.matchers.string.shouldBeUpperCase44import io.kotest.matchers.string.shouldContain45import io.kotest.matchers.string.shouldNotBeBlank46import java.time.LocalDate47import org.junit.jupiter.api.Test48/**49 * Kotest assertions50 *51 * - [Kotest Assertions Documentation](https://kotest.io/assertions/)52 * - [Github](https://github.com/kotest/kotest/)53 */54class FailingKotestAsserts {55 @Test56 fun `General assertions`() {57 assertSoftly {58 "text" shouldBe "txet"59 "hi".shouldBeBlank()60 " ".shouldNotBeBlank()61 "hi".shouldBeEmpty()62 "hi".shouldBeUpperCase()63 "hello".shouldContain("hi")64 false.shouldBeTrue()65 true.shouldBeFalse()66 "not null".shouldBeNull()67 10 shouldBeLessThan 1068 10 shouldBeLessThanOrEqual 969 11 shouldBeGreaterThan 1170 11 shouldBeGreaterThanOrEqual 1271 9.shouldBeEven()72 1.shouldBeZero()73 }74 }75 @Test76 fun `Exception assertions`() {77 assertSoftly {78 shouldThrowExactly<IllegalArgumentException> {79 angryFunction()80 }81 shouldThrowAny {82 "I'm not throwing anything"83 }84 }85 }86 @Test87 fun `Collection assertions`() {88 assertSoftly {89 listOf(1, 2, 3).shouldBeEmpty()90 listOf(1, 2, 3) shouldContain 491 listOf(1, 3, 2).shouldBeSorted()92 listOf(1, 2, 3, 4) shouldBeSameSizeAs listOf(4, 5, 6)93 1 shouldBeOneOf listOf(2, 3)94 mapOf(1 to "one", 2 to "two", 3 to "three").shouldBeEmpty()95 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainKey 496 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainValue "five"97 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContain (6 to "six")98 }99 }100 @Test101 fun `Arrow assertions`() {102 assertSoftly {103 val optionNone = none<String>()104 val optionSome = Some("I am something").toOption()105 optionSome.shouldBeNone()106 optionNone.shouldBeSome()107 val rightEither = Either.Right(1)108 val leftEither = Either.Left("ERROR!!")109 leftEither.shouldBeRight()110 leftEither shouldBeRight 1111 rightEither.shouldBeLeft()112 rightEither shouldBeLeft "ERROR!!"113 val nonEmptyList = NonEmptyList.of(1, 2, 3, 4, 5)114 nonEmptyList shouldContain 6115 nonEmptyList.shouldContainNull()116 val valid = Validated.valid()117 val invalid = Validated.invalid()118 invalid.shouldBeValid()119 valid.shouldBeInvalid()120 }121 }122 @Test123 fun `Json assertions`() {124 val jsonString = "{\"test\": \"property\", \"isTest\": true }"125 assertSoftly {126 jsonString shouldMatchJson "{\"test\": \"otherProperty\"}"127 jsonString shouldContainJsonKey "$.anotherTest"128 jsonString shouldNotContainJsonKey "$.test"129 jsonString.shouldContainJsonKeyValue("$.isTest", false)130 }131 }132 @Test133 fun `Custom assertions`() {134 assertSoftly {135 val sentMail = Mail(136 dateCreated = LocalDate.of(2020, 10, 27),137 sent = true, message = "May you have an amazing day"138 )139 val unsentMail = Mail(140 dateCreated = LocalDate.of(2020, 10, 27),141 sent = false, message = "May you have an amazing day"142 )143 // This is possible144 unsentMail.sent should beSent()145 sentMail.sent shouldNot beSent()146 // This is recommended147 unsentMail.shouldBeSent()148 sentMail.shouldNotBeSent()149 }150 }151 @Test152 fun `withClue usage`() {153 val mail = Mail(154 dateCreated = LocalDate.of(2020, 10, 27),155 sent = false, message = "May you have an amazing day"156 )157 withClue("sent field should be true") {158 mail.sent shouldBe true159 }160 mail.asClue {161 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)162 it.sent shouldBe true163 }164 }165 @Test166 fun `asClue usage`() {167 val mail = Mail(168 dateCreated = LocalDate.of(2020, 10, 27),169 sent = false, message = "May you have an amazing day"170 )171 mail.asClue {172 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)173 it.sent shouldBe true174 }175 }176 fun beSent() = object : Matcher<Boolean> {177 override fun test(value: Boolean) = MatcherResult(value, "Mail.sent should be true", "Mail.sent should be false")178 }179 fun Mail.shouldBeSent() = this.sent should beSent()180 fun Mail.shouldNotBeSent() = this.sent shouldNot beSent()181}182data class Mail(val dateCreated: LocalDate, val sent: Boolean, val message: String)183fun angryFunction() {184 throw IllegalStateException("How dare you!")185}...

Full Screen

Full Screen

KotestAsserts.kt

Source:KotestAsserts.kt Github

copy

Full Screen

1package testing.asserts2import arrow.core.*3import io.kotest.assertions.arrow.either.shouldBeLeft4import io.kotest.assertions.arrow.either.shouldBeRight5import io.kotest.assertions.arrow.nel.shouldContain6import io.kotest.assertions.arrow.nel.shouldContainNull7import io.kotest.assertions.arrow.option.shouldBeNone8import io.kotest.assertions.arrow.option.shouldBeSome9import io.kotest.assertions.arrow.validation.shouldBeInvalid10import io.kotest.assertions.arrow.validation.shouldBeValid11import io.kotest.assertions.asClue12import io.kotest.assertions.json.*13import io.kotest.assertions.throwables.shouldThrowAny14import io.kotest.assertions.throwables.shouldThrowExactly15import io.kotest.assertions.withClue16import io.kotest.matchers.Matcher17import io.kotest.matchers.MatcherResult18import io.kotest.matchers.booleans.shouldBeFalse19import io.kotest.matchers.booleans.shouldBeTrue20import io.kotest.matchers.collections.shouldBeEmpty21import io.kotest.matchers.collections.shouldBeOneOf22import io.kotest.matchers.collections.shouldBeSameSizeAs23import io.kotest.matchers.collections.shouldBeSorted24import io.kotest.matchers.collections.shouldContain25import io.kotest.matchers.date.shouldBeAfter26import io.kotest.matchers.ints.shouldBeEven27import io.kotest.matchers.ints.shouldBeGreaterThan28import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual29import io.kotest.matchers.ints.shouldBeLessThan30import io.kotest.matchers.ints.shouldBeLessThanOrEqual31import io.kotest.matchers.ints.shouldBeZero32import io.kotest.matchers.maps.shouldBeEmpty33import io.kotest.matchers.maps.shouldContain34import io.kotest.matchers.maps.shouldContainKey35import io.kotest.matchers.maps.shouldContainValue36import io.kotest.matchers.nulls.shouldBeNull37import io.kotest.matchers.should38import io.kotest.matchers.shouldBe39import io.kotest.matchers.shouldNot40import io.kotest.matchers.string.shouldBeBlank41import io.kotest.matchers.string.shouldBeEmpty42import io.kotest.matchers.string.shouldBeUpperCase43import io.kotest.matchers.string.shouldContain44import io.kotest.matchers.string.shouldNotBeBlank45import java.time.LocalDate46import org.junit.jupiter.api.Test47/**48 * Kotest assertions49 *50 * - [Kotest Assertions Documentation](https://kotest.io/assertions/)51 * - [Github](https://github.com/kotest/kotest/)52 */53class KotestAsserts {54 @Test55 fun `General assertions`() {56 "text" shouldBe "text"57 " ".shouldBeBlank()58 "hi".shouldNotBeBlank()59 "".shouldBeEmpty()60 "HI".shouldBeUpperCase()61 "hello".shouldContain("ll")62 true.shouldBeTrue()63 false.shouldBeFalse()64 null.shouldBeNull()65 10 shouldBeLessThan 1166 10 shouldBeLessThanOrEqual 1067 11 shouldBeGreaterThan 1068 11 shouldBeGreaterThanOrEqual 1169 10.shouldBeEven()70 0.shouldBeZero()71 }72 @Test73 fun `Exception assertions`() {74 shouldThrowExactly<IllegalStateException> {75 angryFunction()76 }77 shouldThrowAny {78 angryFunction()79 }80 }81 @Test82 fun `Collection assertions`() {83 emptyList<Int>().shouldBeEmpty()84 listOf(1, 2, 3) shouldContain 385 listOf(1, 2, 3).shouldBeSorted()86 listOf(1, 2, 3) shouldBeSameSizeAs listOf(4, 5, 6)87 1 shouldBeOneOf listOf(1, 2, 3)88 emptyMap<Int, String>().shouldBeEmpty()89 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainKey 190 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainValue "two"91 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContain (3 to "three")92 }93 @Test94 fun `Arrow assertions`() {95 val optionNone = none<String>()96 val optionSome = Some("I am something").toOption()97 optionNone.shouldBeNone()98 optionSome.shouldBeSome()99 val rightEither = Either.Right(1)100 val leftEither = Either.Left("ERROR!!")101 rightEither.shouldBeRight()102 rightEither shouldBeRight 1103 leftEither.shouldBeLeft()104 leftEither shouldBeLeft "ERROR!!"105 val nonEmptyList = NonEmptyList.of(1, 2, 3, 4, 5, null)106 nonEmptyList shouldContain 1107 nonEmptyList.shouldContainNull()108 val valid = Validated.valid()109 val invalid = Validated.invalid()110 valid.shouldBeValid()111 invalid.shouldBeInvalid()112 }113 @Test114 fun `Json assertions`() {115 val jsonString = "{\"test\": \"property\", \"isTest\": true }"116 jsonString shouldMatchJson jsonString117 jsonString shouldContainJsonKey "$.test"118 jsonString shouldNotContainJsonKey "$.notTest"119 jsonString.shouldContainJsonKeyValue("$.isTest", true)120 }121 @Test122 fun `Custom assertions`() {123 val sentMail = Mail(124 dateCreated = LocalDate.of(2020, 10, 27),125 sent = true, message = "May you have an amazing day"126 )127 val unsentMail = Mail(128 dateCreated = LocalDate.of(2020, 10, 27),129 sent = false, message = "May you have an amazing day"130 )131 // This is possible132 sentMail.sent should beSent()133 unsentMail.sent shouldNot beSent()134 // This is recommended135 sentMail.shouldBeSent()136 unsentMail.shouldNotBeSent()137 }138 @Test139 fun `withClue usage`() {140 val mail = Mail(141 dateCreated = LocalDate.of(2020, 10, 27),142 sent = false, message = "May you have an amazing day"143 )144 withClue("sent field should be false") {145 mail.sent shouldBe false146 }147 mail.asClue {148 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)149 it.sent shouldBe false150 }151 }152 @Test153 fun `asClue usage`() {154 val mail = Mail(155 dateCreated = LocalDate.of(2020, 10, 27),156 sent = false, message = "May you have an amazing day"157 )158 mail.asClue {159 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)160 it.sent shouldBe false161 }162 }163 fun beSent() = object : Matcher<Boolean> {164 override fun test(value: Boolean) = MatcherResult(value, "Mail.sent should be true", "Mail.sent should be false")165 }166 fun Mail.shouldBeSent() = this.sent should beSent()167 fun Mail.shouldNotBeSent() = this.sent shouldNot beSent()168}169data class Mail(val dateCreated: LocalDate, val sent: Boolean, val message: String)170fun angryFunction() {171 throw IllegalStateException("How dare you!")172}...

Full Screen

Full Screen

KotlinTest.kt

Source:KotlinTest.kt Github

copy

Full Screen

1package com.example.sampletestcode2import io.kotest.core.spec.style.*3import io.kotest.matchers.collections.sorted4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.string.*7import io.kotest.matchers.collections.beEmpty8import io.kotest.matchers.maps.contain9import io.kotest.matchers.maps.haveKey10import io.kotest.matchers.maps.haveValue11class StringSpecTest : StringSpec() {12 // StringSpec를 상속 받으며, 보통 init 블럭 내에서 테스트 코드를 작성한다.13 // init 블록 내부의 문자열은 테스트를 설명하는 부분이며, 블럭 내부의 코드가 실제 테스트가 진행되는 부분이다.14 init {15 "문자열.length가 문자열의 길이를 리턴해야 합니다." {16 "kotlin test".length shouldBe 1117 }18 }19}20class FunSpecTest : FunSpec({21 // FunSpec는 함수 형태로 테스트 코드를 작성할 수 있도록 돕는다.22 // 테스트 함수의 매개 변수는 단순 테스트 설명이며, 테스트 함수 내부의 코드가 실제 테스트가 진행되는 부분이다.23 test("문자열의 길이를 리턴해야 합니다.") {24 "kotlin".length shouldBe 625 "".length shouldBe 026 }27})28class ShouldSpecTest : ShouldSpec({29 // ShouldSpec는 FunSpec과 유사하다. 다만, test 대신 should 키워드를 사용한다는 차이점이 있다.30 // 아래 should 의 매개 변수는 단순 설명이고, 테스트는 역시 블럭 내부에서 동작한다.31 should("문자열의 길이를 리턴해야 합니다.") {32 "kotlin".length shouldBe 633 "".length shouldBe 034 }35})36class WordSpecTest : WordSpec({37 // String.length 부분은 context string이다. 어떠한 환경에서 테스트를 진행할 것인지를 말해 주는 것이다.38 // 아래 한글은 역시 설명 부분이며, 코드 블럭 내부에서 실제 테스트가 동작한다.39 "String.length" should {40 "문자열의 길이를 리턴해야 합니다." {41 "kotlin".length shouldBe 642 "".length shouldBe 043 }44 }45})46class BehaviorSpecTest : BehaviorSpec({47 // BehaviorSpec는 BDD (Behaviour Driven Development)48 given("젓가락") {49 `when`("잡는다.") {50 then("음식을 먹는다.") {51 println("젓가락을 잡고, 음식을 먹는다.")52 }53 }54 `when`("던진다.") {55 then("사람이 맞는다.") {56 println("젓가락을 던지면, 사람이 맞는다.")57 }58 }59 }60})61class AnnotationSpecTest : AnnotationSpec() {62 // AnnotationSpec는 JUnit 스타일(PersonTest 파일 참고)로 테스트 코드를 작성할 수 있다.63 @BeforeEach64 fun beforeTest() {65 println("Before Test, Setting")66 }67 @Test68 fun test1() {69 "test".length shouldBe 470 }71 @Test72 fun test2() {73 "test2".length shouldBe 574 }75}76class MatcherTest : StringSpec() {77 init {78 // shouldBe는 동일함을 체크하는 Matcher 이다.79 "hello World" shouldBe haveLength(11) // length가 매개변수에 전달된 값이어야 함을 체크한다.80 "hello" should include("ll") // 매개변수 값이 포함되어 있는지 확인한다.81 "hello" should endWith("lo") // 매개변수의 끝이 포함되는지 확인한다.82 "hello" should match("he...") // 매개변수가 매칭되는지 체크한다.83 "hello".shouldBeLowerCase() // 소문자로 작성된 것이 맞는지 체크한다.84 val list = emptyList<String>()85 val list2 = listOf("aaa", "bbb", "ccc")86 val map = mapOf<String, String>(Pair("aa", "11"))87 list should beEmpty() // 원소가 비었는지 확인한다....

Full Screen

Full Screen

04_PropertyBasedStrategies.kt

Source:04_PropertyBasedStrategies.kt Github

copy

Full Screen

1package property.based.testing2import io.kotest.core.spec.style.ShouldSpec3import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder4import io.kotest.matchers.collections.shouldHaveSize5import io.kotest.matchers.maps.shouldContain6import io.kotest.matchers.shouldBe7import io.kotest.property.Arb8import io.kotest.property.arbitrary.int9import io.kotest.property.arbitrary.list10import io.kotest.property.checkAll11@Suppress("Unused")12class PropertyBasedStrategies : ShouldSpec({13 context("different paths, same destination") {14 xshould("negate and sort list") {15 checkAll(Arb.list(Arb.int(-10_000, 10_000))) { a ->16 a.map(Int::unaryMinus).sorted() shouldBe a.sorted().map(Int::unaryMinus).reversed()17 }18 }19 xshould("append then reverse is same like reverse then prepend") {20 checkAll(Arb.int(), Arb.list(Arb.int(-10_000, 10_000))) { additionalItem, list ->21 val appendThenReverse = list.appended(additionalItem).asReversed()22 val reversedThenPrepended = list.asReversed().prepended(additionalItem)23 appendThenReverse shouldBe reversedThenPrepended24 }25 }26 }27 context("there and back again") {28 xshould("insert - contains") {29 checkAll<Int, String> { a, b ->30 val myMap = mapOf(a to b)31 myMap shouldContain (a to b)32 }33 }34 xshould("serialization - deserialization") {35 checkAll(Arb.person()) { person ->36 JsonSerializer.fromString(JsonSerializer.toString(person)) shouldBe person37 }38 }39 }40 context("some things never change") {41 xshould("size of sorted list") {42 checkAll<List<Int>> { a ->43 a.sorted() shouldHaveSize a.size44 }45 }46 xshould("contain exactly same elements") {47 checkAll<List<Int>> { a ->48 a.sorted() shouldContainExactlyInAnyOrder a49 }50 }51 }52 context("The more things change, the more they stay the same") {53 xshould("filtering twice is same as filtering once") {54 checkAll<List<Int>> { a ->55 a.filter(::isEven).filter(::isEven) shouldContainExactlyInAnyOrder a.filter(::isEven)56 }57 }58 xshould("trim a string multiple times is same as trim it once") {59 checkAll<String> { a ->60 a.trim().trim().trim() shouldBe a.trim()61 }62 }63 }64 context("Solve a smaller problem first") {65 }66 context("Hard to prove, easy to verify") {67 xshould("prime factor") {68 checkAll(Arb.int(1..100)) { a ->69 a.primeFactors().reduce(Int::times) shouldBe a70 }71 }72 }73 context("The test oracle") {74 // naive vs optimized version75 xshould("test again an other implementation, maybe a not performant one") {76 checkAll<Int, Int> { a, b ->77 add(a, b) shouldBe a + b78 }79 }80 }81})82private fun List<Int>.appended(additionalItem: Int): List<Int> =83 this + additionalItem84private fun List<Int>.prepended(additionalItem: Int): List<Int> =85 also { myList ->86 val intermediateList = myList.toMutableList()87 intermediateList.add(0, additionalItem)88 intermediateList.toList()89 }...

Full Screen

Full Screen

MatcherTest.kt

Source:MatcherTest.kt Github

copy

Full Screen

1package com.psg.kotest_example2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.collections.sorted4import io.kotest.matchers.maps.contain5import io.kotest.matchers.maps.haveKey6import io.kotest.matchers.maps.haveValue7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.matchers.string.*10class MatcherTest : StringSpec() {11 init {12 // 'shouldBe' 동일함을 체크하는 Matcher 입니다.13 "hello world" shouldBe haveLength(11) // length가 11이어야 함을 체크 합니다.14 "hello" should include("ll") // 파라미터가 포함되어 있는지 체크 합니다.15 "hello" should endWith("lo") // 파라미터가 끝의 포함되는지 체크 합니다.16 "hello" should match("he...") // 파라미터가 매칭되는지 체크 합니다.17 "hello".shouldBeLowerCase() // 소문자로 작성되었는지 체크 합니다.18 val list = emptyList<String>()19 val list2 = listOf("aaa", "bbb", "ccc")20 val map = mapOf<String, String>(Pair("aa", "11"))21 list should beEmpty() // 원소가 비었는지 체크 합니다.22 list2 shouldBe sorted<String>() // 해당 자료형이 정렬 되었는지 체크 합니다.23 map should contain("aa", "11") // 해당 원소가 포함되었는지 체크 합니다....

Full Screen

Full Screen

ExampleUnitTest.kt

Source:ExampleUnitTest.kt Github

copy

Full Screen

1package pl.gdg.myapplication2import io.kotest.matchers.collections.shouldBeSortedWith3import io.kotest.matchers.collections.shouldNotContain4import io.kotest.matchers.ints.shouldBeExactly5import org.junit.Assert.assertEquals6import org.junit.Test7/**8 * Example local unit test, which will execute on the development machine (host).9 *10 * See [testing documentation](http://d.android.com/tools/testing).11 */12class ExampleUnitTest {13 @Test14 fun addition_isCorrect() {15 assertEquals(4, 2 + 2)16 }17 @Test18 fun `addition is correct`() {19 2 + 2 shouldBeExactly 420 }21 @Test22 fun `list contains odd numbers`() {23 listOf(1, 3, 5) shouldNotContain 724 listOf(1, 3, 5) shouldBeSortedWith Int::compareTo...

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1 test("sorted") {2 sorted(listOf(1, 2, 3)) shouldBe listOf(1, 2, 3)3 sorted(listOf(3, 2, 1)) shouldBe listOf(1, 2, 3)4 sorted(listOf(1, 3, 2)) shouldBe listOf(1, 2, 3)5 sorted(listOf(1, 2, 3), reverseOrder()) shouldBe listOf(3, 2, 1)6 }7})8 test("sorted") {9 listOf(1, 2, 3) shouldBeSorted { a, b -> a < b }10 listOf(3, 2, 1) shouldBeSorted { a, b -> a > b }11 listOf(1, 2, 3) shouldBeSorted reverseOrder()12 }13})14 test("sorted") {15 listOf(1, 2, 3) shouldBeSortedWith naturalOrder()16 listOf(3, 2, 1) shouldBeSortedWith reverseOrder()17 }18})19 test("sorted") {20 listOf(1, 2, 3) shouldBeSortedBy { it }21 listOf(3, 2, 1) shouldBeSortedBy { -it }22 }23})24 test("sorted") {25 listOf(1, 2, 3) shouldBeSortedByDescending { -it }26 listOf(3, 2, 1) shouldBeSortedByDescending { it }27 }28})29 test("sorted") {30 listOf(1, 2, 3) shouldBeSortedBy { it }31 listOf(3, 2, 1) shouldBeSortedBy { -it }32 }33})

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1list should sorted().reverse()2list should sorted().by { a, b -> a > b }3list should sorted().by { a, b -> a > b }4list should sorted().by { a, b -> a > b }5list should sorted().by { a, b -> a > b }6list should sorted().by { a, b -> a > b }7list should sorted().by { a, b -> a > b }8list should sorted().by { a, b -> a > b }9list should sorted().by { a, b -> a > b }10list should sorted().by { a, b -> a > b }11list should sorted().by { a, b -> a > b }12list should sorted().by { a, b -> a > b }13The sorted matcher also supports a by() method which allows you to specify a comparator function to check the list against

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 method in sorted

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful