How to use contain method of io.kotest.matchers.string.matchers class

Best Kotest code snippet using io.kotest.matchers.string.matchers.contain

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

WordRiddleSpec.kt

Source:WordRiddleSpec.kt Github

copy

Full Screen

...33                        }34                    }35                    When("Guess lower case ${letter.lowercaseChar()}") {36                        riddle.guess(letter)37                        Then("Guessed letters should contain $letter") {38                            guessedLetters shouldContain letter.lowercaseChar()39                        }40                    }41                    When("Guess upper case ${letter.uppercaseChar()}") {42                        riddle.guess(letter)43                        Then("Guessed letters should contain $letter") {44                            guessedLetters shouldContain letter.lowercaseChar()45                        }46                    }47                }48                And("Another letter") {49                    val letter = 'a'50                    When("Check if $letter is left") {51                        val left = riddle.left(letter)52                        Then("The riddle should not have $letter left") {53                            left shouldNotBe true54                        }55                    }56                    When("Guess $letter") {57                        riddle.guess(letter)58                        Then("$letter should not be guessed") {59                            guessedLetters.shouldBeEmpty()60                        }61                    }62                }63                When("Write riddle") {64                    riddle.write(writer)65                    Then("Writer string should contain masked word") {66                        writer.toString() shouldBe "??????????"67                    }68                }69            }70        }71        And("All letters from the word collection") {72            val guessedLetters = mutableSetOf('s', 'i', 'm', 'p', 'l', 'c', 't', 'y')73            And("Word riddle") {74                val riddle = WordRiddle(word, guessedLetters)75                When("Check if the riddle is guessed") {76                    val guessed = riddle.guessed()77                    Then("Riddle should be guessed") {78                        guessed shouldBe true79                    }80                }81                And("Letter from the word") {82                    val letter = 'o'83                    When("Check if $letter is left") {84                        val left = riddle.left(letter)85                        Then("The riddle should not have $letter left") {86                            left shouldBe false87                        }88                    }89                }90                When("Write riddle") {91                    riddle.write(writer)92                    Then("Writer string should contain unmasked word") {93                        writer.toString() shouldBe "simplicity"94                    }95                }96            }97        }98    }99})...

Full Screen

Full Screen

InMemoryHopRepositoryTest.kt

Source:InMemoryHopRepositoryTest.kt Github

copy

Full Screen

1package infrastructure2import domain.country.model.Country3import domain.hop.model.Hop4import domain.hop.model.HopType5import domain.quantities.PercentRange6import domain.quantities.QuantityRange7import fixtures.sampleHop8import io.kotest.assertions.assertSoftly9import io.kotest.assertions.fail10import io.kotest.core.spec.style.ShouldSpec11import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder12import io.kotest.matchers.maps.shouldHaveSize13import io.kotest.matchers.nulls.shouldNotBeNull14import io.kotest.matchers.shouldBe15import io.kotest.matchers.string.shouldNotBeBlank16class InMemoryHopRepositoryTest : ShouldSpec({17    val repoUnderTest = InMemoryHopRepository()18    beforeEach {19        repoUnderTest.clear()20    }21    should("find hop by name") {22        // Givent23        repoUnderTest.save(sampleHop)24        repoUnderTest.save(sampleHop.copy(name = "Cascade", similarTo = listOf("Citra")))25        repoUnderTest.save(sampleHop.copy(name = "Chinook", similarTo = listOf("Cascade", "Citra", "Chinook")))26        // When & Then27        repoUnderTest.findByName("Citra").shouldNotBeNull().apply {28            assertSoftly {29                name shouldBe "Citra"30                country.shouldContainExactlyInAnyOrder(Country.USA)31                alpha shouldBe PercentRange(10.0, 12.0)32                beta shouldBe PercentRange(3.5, 4.5)33                coH shouldBe PercentRange(22.0, 24.0)34                type.shouldContainExactlyInAnyOrder(HopType.AROMATIC, HopType.BITTERING)35                profile.shouldNotBeBlank()36                similarTo.shouldContainExactlyInAnyOrder("Cascade", "Centennial", "Chinook")37            }38        }39    }40    should("get all") {41        // Given42        repoUnderTest.save(sampleHop)43        repoUnderTest.save(sampleHop.copy(name = "Cascade", similarTo = listOf("Citra")))44        repoUnderTest.save(sampleHop.copy(name = "Chinook", similarTo = listOf("Cascade", "Citra", "Chinook")))45        // When46        val res = repoUnderTest.getAll()47        // Then48        res shouldHaveSize 349        res["CASCADE"] shouldBe Hop(50            name = "Cascade",51            country = listOf(Country.USA),52            alpha = PercentRange(from = 10.0, to = 12.0),53            beta = PercentRange(from = 3.5, to = 4.5),54            coH = PercentRange(from = 22.0, to = 24.0),55            oil = QuantityRange(from = 1.5, to = 3.0),56            type = listOf(HopType.BITTERING, HopType.AROMATIC),57            profile = "Agrumes, pamplemousse, fruit de la passion",58            similarTo = listOf("Citra"),59        )60    }61    should("find all similar hops") {62        // Given63        repoUnderTest.save(sampleHop)64        repoUnderTest.save(sampleHop.copy(name = "Cascade", similarTo = listOf("Citra")))65        repoUnderTest.save(sampleHop.copy(name = "Centennial", similarTo = emptyList()))66        repoUnderTest.save(sampleHop.copy(name = "Chinook", similarTo = listOf("Cascade", "Citra", "Centennial")))67        val rootHop = repoUnderTest.findByName("Chinook") ?: fail("initialization error")68        // When & Then69        repoUnderTest.findSimilar(rootHop).shouldContainExactlyInAnyOrder(70            repoUnderTest.findByName("Cascade"),71            repoUnderTest.findByName("Centennial"),72            repoUnderTest.findByName("Citra"),73        )74    }75})...

Full Screen

Full Screen

MyTest.kt

Source:MyTest.kt Github

copy

Full Screen

1package kotest2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.inspectors.forAtLeast4import io.kotest.inspectors.forAtMost5import io.kotest.matchers.equality.shouldBeEqualToComparingFields6import io.kotest.matchers.equality.shouldBeEqualToComparingFieldsExcept7import io.kotest.matchers.equality.shouldNotBeEqualToComparingFields8import io.kotest.matchers.equality.shouldNotBeEqualToComparingFieldsExcept9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNotBe11import io.kotest.matchers.string.shouldContain12import io.kotest.matchers.string.shouldHaveMaxLength13import io.kotest.matchers.string.shouldHaveMinLength14import io.kotest.matchers.string.shouldStartWith15import org.junit.jupiter.api.Test16import java.io.FileNotFoundException17class MyTest {18    @Test19    fun shouldBe_shouldNotBe() {20        val name = "sam";21        name shouldBe "sam"22        name shouldNotBe "jack"23    }24    @Test25    fun shouldContain() {26        val name = "anyOne"27        name shouldContain "One" shouldStartWith "any"28        name.shouldContain("One").shouldStartWith("any")29    }30    @Test31    fun inspectors_test() {32        val xs = listOf("sam", "gareth", "timothy", "muhammad")33        xs.forAtLeast(2) {34            it.shouldHaveMinLength(7)35        }36        xs.forAtMost(1) {37            it.shouldHaveMaxLength(3)38        }39    }40    class Foo(_id: Int, _description: String = "", _secret: String = "") {41        val id: Int = _id;42        val description: String = _description;43        private val secret: String = _secret;44    }45    @Test46    fun shouldBeEqualToComparingFields() {47        val foo1 = Foo(1, "Foo1")48        val foo2 = Foo(1, "Foo1")49        foo1.shouldBeEqualToComparingFields(foo2)50        val foo3 = Foo(1, "", _secret = "A")51        val foo4 = Foo(1, "", _secret = "B")52        foo1.shouldBeEqualToComparingFields(foo2)53    }54    @Test55    fun shouldBeEqualToComparingFields_ignorePrivateFields() {56        val foo1 = Foo(1, _secret = "A")57        val foo2 = Foo(1, _secret = "B")58        foo1.shouldNotBeEqualToComparingFields(foo2, false)59        foo1.shouldBeEqualToComparingFields(foo2, true)60    }61    @Test62    fun shouldBeEqualToComparingFieldsExcept() {63        val foo1 = Foo(1, "Foo1")64        val foo2 = Foo(1, "Foo2")65        foo1.shouldBeEqualToComparingFieldsExcept(foo2, Foo::description)66    }67    @Test68    fun shouldBeEqualToComparingFieldsExcept_ignorePrivate() {69        val foo1 = Foo(1, "Foo1", "A")70        val foo2 = Foo(1, "Foo2", "B")71        foo1.shouldNotBeEqualToComparingFieldsExcept(foo2, false, Foo::description)72        foo1.shouldBeEqualToComparingFieldsExcept(foo2, true, Foo::description)73    }74    @Test75    fun shouldThrow() {76        val exception = shouldThrow<FileNotFoundException> {77            throw FileNotFoundException("Something went wrong")78        }79        exception.message.shouldStartWith("Something went wrong")80    }81    class Person(private val fieldA: String, private val fieldB: String)82    @Test83    fun test () {84        val  person1 = Person("valueA", "valueB")85        val  person2 = Person("valueA", "XXX")86//        person1.shouldBeEqualToComparingFieldsExcept(person2, Person::fieldB);87    }88}...

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") // 해당 원소가 포함되었는지 체크 합니다.24        map should haveKey("aa") // 해당 key가 포함되었는지 체크 합니다.25        map should haveValue("11") // 해당 value가 포함되었는지 체크 합니다.26    }27}...

Full Screen

Full Screen

ParserTest.kt

Source:ParserTest.kt Github

copy

Full Screen

1import io.kotest.core.spec.style.StringSpec2import io.kotest.matchers.be3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.comparables.shouldBeEqualComparingTo5import io.kotest.matchers.maps.shouldContain6import io.kotest.matchers.maps.shouldNotContainKey7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.matchers.shouldNot10import io.kotest.matchers.string.endWith11import io.kotest.matchers.string.shouldNotContain12import io.kotest.matchers.string.startWith13import io.kotest.property.Arb14import io.kotest.property.arbitrary.next15import io.kotest.property.arbitrary.string16import io.kotest.property.checkAll17import org.jsoup.Jsoup18import org.jsoup.select.Elements19//TODO("")20class SanitzeHtmlSpec : StringSpec({21    "No soft hypen in replaced characters" {22        val arb = Arb.string()23        arb.checkAll(99000) {24            a ->25            val result = sanitizeHtml(a)26            result shouldNotContain  "\u00AD"27        }28    }29    "Specifically trigger soft hypen in previous result" {30        val result = sanitizeHtml("&nbsptestword")31        result shouldNotContain "\u00AD"32        result shouldBe "testword"33    }34    "Strong should be filtered from software" {35        var arb = Arb.string()36        arb.checkAll { a ->37            val word = a + "<strong>" + arb.next()38            val result = sanitizeHtml(word)39            result shouldNotContain "<strong>"40        }41    }42    "Trigger the test in another way" {43        val result = sanitizeHtml("<strong>")44        result shouldNot be("\u00AD")45        result shouldBe ""46    }47})48class ParserTest : StringSpec({49    "C" {50        Model.items["in"] = 1751        Model.filter()52        for(banWord in Model.bansWord) {53            Model.items shouldNotContainKey banWord54        }55    }56})...

Full Screen

Full Screen

KoTestTest.kt

Source:KoTestTest.kt Github

copy

Full Screen

...11class KoTestTest {12    private val animals = listOf("Rex", "Caramel", "Joe", "Anna")13    @Test14    fun kotest() {15        animals should containPalyndrom()16        animals17            .shouldBeInstanceOf<List<String>>()18            .shouldContain("Rex") // Doesn't let me chain here19        animals.shouldNotContain("Snow") // Doesn't let me chain here20        animals.shouldHaveSize(3)21    }22    @Test23    fun kotestSoftList() {24        assertSoftly {25            animals.shouldHaveSize(2)26            animals27                .shouldBeInstanceOf<List<String>>()28                .shouldContain("Rex") // Doesn't let me chain here29            animals.shouldNotContain("Snow") // Doesn't let me chain here30            animals.shouldHaveSize(3)31        }32    }33    fun containPalyndrom() = object : Matcher<List<String>> {34        override fun test(value: List<String>): MatcherResult {35            return MatcherResult(36                value.any { it.reversed().equals(it, ignoreCase = true) },37                "List should contain palindrome",38                "List shouldn't contain palindrome"39            )40        }41    }42}...

Full Screen

Full Screen

contain

Using AI Code Generation

copy

Full Screen

1"hello" should contain("h")2"hello" shouldNot contain("z")3"hello" should startWith("h")4"hello" should endWith("o")5"hello" shouldNot startWith("z")6"hello" shouldNot endWith("z")7"hello" should haveLength(5)8"hello" shouldNot haveLength(6)9"" should beEmpty()10"hello" shouldNot beEmpty()11"" should beBlank()12" " should beBlank()13"hello" shouldNot beBlank()14"" should beEmptyOrBlank()15" " should beEmptyOrBlank()16"hello" shouldNot beEmptyOrBlank()17"1234" should containOnlyDigits()18"1234a" shouldNot containOnlyDigits()19"abcd" should containOnlyLetters()20"abcd1" shouldNot containOnlyLetters()21"abcd" should containOnlyDigitsOrLetters()22"abcd1" should containOnlyDigitsOrLetters()23"abcd1!" shouldNot containOnlyDigitsOrLetters()24" " should containOnlyWhitespace()25"  " should containOnlyWhitespace()26" 1 " shouldNot containOnlyWhitespace()27"hello" should containOnlyOnce("l")28"hello" shouldNot containOnlyOnce("z")29"hello" should containAnyOf("h", "z")30"hello" shouldNot containAnyOf("z", "x")

Full Screen

Full Screen

contain

Using AI Code Generation

copy

Full Screen

1    "contains" should "return true if string contains substring" {2        "hello" should contain("hello")3        "hello" should contain("hell")4        "hello" should contain("llo")5        "hello" should contain("ell")6        "hello" should contain("he")7        "hello" should contain("lo")8        "hello" should contain("ll")9        "hello" should contain("el")10        "hello" should contain("h")11        "hello" should contain("o")12        "hello" should contain("l")13        "hello" should contain("e")14    }15    "startsWith" should "return true if string starts with substring" {16        "hello" should startWith("hello")17        "hello" should startWith("hell")18        "hello" should startWith("hel")19        "hello" should startWith("he")20        "hello" should startWith("h")21    }22    "endsWith" should "return true if string ends with substring" {23        "hello" should endWith("hello")24        "hello" should endWith("ello")25        "hello" should endWith("llo")26        "hello" should endWith("lo")27        "hello" should endWith("o")28    }29    "beEmpty" should "return true if string is empty" {30        "" should beEmpty()31        " " shouldNot beEmpty()32        "hello" shouldNot beEmpty()33    }34    "beBlank" should "return true if string is blank" {35        "" should beBlank()36        " " should beBlank()37        "hello" shouldNot beBlank()38    }39    "beEmpty" should "return true if string is empty" {40        "" should beEmpty()41        " " shouldNot beEmpty()42        "hello" shouldNot beEmpty()43    }

Full Screen

Full Screen

contain

Using AI Code Generation

copy

Full Screen

1fun test() {2str should contain("World")3}4fun test() {5shouldThrow<Exception> {6}7}8fun test() {9shouldNotThrow<Exception> {10}11}12fun test() {13shouldNotThrowAny {14}15}16fun test() {17shouldThrowAny {18}19}20fun test() {21shouldThrowExactly<Exception> {22}23}24fun test() {25shouldThrowExactlyAny {26}27}28fun test() {29shouldThrowExactlyUnit {30}31}32fun test() {33shouldThrowUnit {34}35}36fun test() {37shouldThrowInstanceOf<Exception> {38}39}40fun test() {41shouldThrowInstanceOfAny {42}43}44fun test() {45shouldThrowInstanceOfUnit {46}47}48fun test() {49shouldThrowUnit {

Full Screen

Full Screen

contain

Using AI Code Generation

copy

Full Screen

1fun testStringContains() {2text should contain("Hello")3}4fun testStringStartWith() {5text should startWith("Hello")6}7fun testStringEndWith() {8text should endWith("World")9}10fun testStringMatch() {11text should match(Regex("Hello World"))12}13fun testStringMatch() {14text should match(Regex("Hello World"))15}16fun testStringMatch() {17text should match(Regex("Hello World"))18}19fun testStringMatch() {20text should match(Regex("Hello World"))21}22fun testStringMatch() {23text should match(Regex("Hello World"))24}25fun testStringMatch() {26text should match(Regex("Hello World"))27}28fun testStringMatch() {29text should match(Regex("Hello World"))30}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful