How to use end class of io.kotest.matchers.string package

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

TestSchedule.kt

Source:TestSchedule.kt Github

copy

Full Screen

...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" {34 Schedule.fetch().also { schedule ->35 schedule.calendarYears shouldHaveSize 1836 schedule.calendarYears.map { year -> year.id }.sorted() shouldContainInOrder (2004..2020).toList()37 schedule.calendarYears.forEach {38 it.href.toString() shouldEndWith "${it.year}.xml"39 }40 }41 }42 "should load local 2020.xml properly" {43 "schedule_2020.xml".load().fromXml<ScheduleYear>().also { year ->44 year.terms shouldHaveSize 445 year.terms.forEach {46 it.id shouldStartWith "12020"47 }48 }49 }50 "should load remote 2020.xml properly" {51 ScheduleYear.fetch("2020").also { year ->52 year.terms shouldHaveSize 453 year.terms.forEach {54 it.id shouldStartWith "12020"55 }56 }57 }58 "should load local 2020/fall.xml properly" {59 "schedule_2020_fall.xml".load().fromXml<ScheduleYearSemester>().also { semester ->60 semester.subjects.size shouldBeGreaterThan 061 semester.subjects.find { it.id == "CS" }?.department shouldBe "Computer Science"62 semester.parents.calendarYear.year shouldBe 202063 }64 }65 "should load remote 2020/fall.xml properly" {66 ScheduleYearSemester.fetch("2020", "fall").also { semester ->67 semester.subjects.size shouldBeGreaterThan 068 semester.subjects.find { it.id == "CS" }?.department shouldBe "Computer Science"69 semester.parents.calendarYear.year shouldBe 202070 }71 }72 "should load local 2020/fall/CS.xml properly" {73 "schedule_2020_fall_CS.xml".load().fromXml<ScheduleYearSemesterDepartment>().also { department ->74 department.contactName shouldBe "Nancy Amato"75 department.courses.find { it.id == "125" }?.name shouldBe "Intro to Computer Science"76 department.parents.calendarYear.year shouldBe 202077 department.parents.term.semester shouldBe "Fall 2020"78 }79 }80 "should load remote 2020/fall/CS.xml properly" {81 ScheduleYearSemesterDepartment.fetch("2020", "fall", "CS").also { department ->82 department.contactName shouldBe "Nancy Amato"83 department.courses.find { it.id == "125" }?.name shouldBe "Intro to Computer Science"84 department.parents.calendarYear.year shouldBe 202085 department.parents.term.semester shouldBe "Fall 2020"86 }87 }88 "should load local 2020/fall/CS/100.xml properly" {89 "schedule_2020_fall_CS_100.xml".load().fromXml<Course>().also { course ->90 course.label shouldBe "Freshman Orientation"91 course.href shouldNotBe null92 course.description shouldStartWith "Introduction to Computer Science as a field and career"93 course.creditHours shouldBe "1 hours."94 }95 }96 "should load remote 2020/fall/CS/100.xml properly" {97 Course.fetch("2020", "fall", "CS", "100").also { course ->98 course.label shouldBe "Freshman Orientation"...

Full Screen

Full Screen

ComputeInstanceSpec.kt

Source:ComputeInstanceSpec.kt Github

copy

Full Screen

1package utils2import io.kotest.assertions.fail3import io.kotest.assertions.timing.eventually4import io.kotest.core.spec.style.WordSpec5import io.kotest.matchers.be6import io.kotest.matchers.collections.shouldExist7import io.kotest.matchers.or8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.string.shouldEndWith11import io.kotest.matchers.string.shouldInclude12import io.kotest.matchers.string.shouldNotBeBlank13import kotlinx.coroutines.FlowPreview14import kotlinx.coroutines.async15import kotlinx.coroutines.runBlocking16import kotlinx.serialization.ExperimentalSerializationApi17import utils.Compute.Instance18import kotlin.time.ExperimentalTime19import kotlin.time.minutes20import kotlin.time.seconds21// todo: afterTest Instance.delete22@ExperimentalSerializationApi23@FlowPreview24@ExperimentalTime25class ComputeInstanceSpec : WordSpec({26 val projectId = System.getenv("PROJECT_ID") ?: fail("Must set PROJECT_ID env var")27 val regionId = System.getenv("REGION_ID") ?: fail("Must set REGION_ID env var")28 val dbPass = System.getenv("DB_PASS") ?: fail("Most set DB_PASS env var")29 val dbInstance = System.getenv("DB_INSTANCE") ?: fail("Most set DB_INSTANCE env var")30 val maybeServiceAccount = System.getenv("SERVICE_ACCOUNT")31 val accessToken = Auth.accessTokenFromGcloud(maybeServiceAccount)32 val name = Instance.randomName()33 val zone = "us-central1-a"34 val machineType = "e2-medium"35 val defaultImage = "docker.io/hello-world"36 val testImage = "gcr.io/$projectId/one-off-cloud-run-test"37 val instance1 = Instance(projectId, zone, machineType, defaultImage, name, null, emptyList(), emptyMap(), false)38 val instance2 = instance1.copy(39 name = ""40 )41 val instance3 = instance1.copy(42 name = Instance.randomName(),43 serviceAccountName = maybeServiceAccount44 )45 val instance4 = instance1.copy(46 name = Instance.randomName(),47 containerImage = testImage,48 containerEnvs = mapOf("NAME" to "world"),49 containerEntrypoint = "/bin/sh",50 containerArgs = listOf("-c", "echo \"hello, \$NAME\"")51 )52 val instance5 = instance1.copy(53 name = Instance.randomName(),54 shutdownOnComplete = true55 )56 val instance6 = instance1.copy(57 name = Instance.randomName(),58 containerImage = testImage,59 containerEntrypoint = "psql",60 containerEnvs = mapOf("PGPASSWORD" to dbPass),61 containerArgs = listOf("-h", "/cloudsql/$projectId:$regionId:$dbInstance", "-U", "postgres", "-c", "SELECT 1"),62 instanceConnectionName = "$projectId:$regionId:$dbInstance"63 )64 "instance name" should {65 "not start with a number" {66 instance1.copy(name = "0").validName shouldBe "x-0"67 }68 "not be empty" {69 instance1.copy(name = null).validName.shouldNotBeBlank()70 }71 "fix invalid names" {72 instance1.copy(name = "a/b").validName shouldBe "a-b"73 }74 }75 "an instance" should {76 "be creatable" {77 val operation = Instance.create(instance1, maybeServiceAccount)78 operation.getOrThrow() shouldEndWith "RUNNING"79 }80 "be creatable with an invalid name" {81 val operation = Instance.create(instance2, maybeServiceAccount)82 operation.getOrThrow() shouldEndWith "RUNNING"83 }84 "be describable" {85 val operation = Instance.describe(instance1, maybeServiceAccount)86 operation.getOrThrow().status shouldBe "RUNNING"87 }88 "fail when trying to describe an non-existent instance" {89 val operation = Instance.describe(instance1.copy(name = Instance.randomName()), maybeServiceAccount)90 operation.isFailure shouldBe true91 }92 "be updatable" {93 val operation = Instance.update(instance1, maybeServiceAccount)94 operation.getOrThrow() shouldEndWith "done."95 }96 "be startable" {97 val operation = Instance.start(instance1, maybeServiceAccount)98 operation.getOrThrow() shouldInclude "Updated"99 }100 "be creatable with a custom service account" {101 val operation = Instance.create(instance3, maybeServiceAccount)102 operation.getOrThrow() shouldEndWith "RUNNING"103 Instance.describe(instance3).getOrThrow().serviceAccounts.first().email shouldBe maybeServiceAccount104 }105 "be creatable with a custom entrypoint, args, and env vars" {106 val operation = Instance.create(instance4, maybeServiceAccount)107 operation.getOrThrow() shouldEndWith "RUNNING"108 eventually(2.minutes, 15.seconds) {109 Instance.logs(instance4, 500, accessToken, maybeServiceAccount).getOrThrow() shouldExist { it.jsonPayload?.message?.contains("hello, world") ?: false }110 }111 }112 "shutdown an instance after the docker process stops" {113 val createOperation = Instance.create(instance5, maybeServiceAccount)114 createOperation.getOrThrow() shouldEndWith "RUNNING"115 // wait for the shutdown script to run116 eventually(3.minutes, 15.seconds) {117 val operation = Instance.describe(instance5, maybeServiceAccount)118 val status = operation.getOrThrow().status119 status should (be("TERMINATED") or be("STOPPED"))120 }121 }122 "work with Cloud SQL" {123 val operation = Instance.create(instance6, maybeServiceAccount)124 operation.getOrThrow() shouldEndWith "RUNNING"125 eventually(2.minutes, 15.seconds) {126 Instance.logs(instance6, 500, accessToken, maybeServiceAccount).getOrThrow() shouldExist { it.jsonPayload?.message?.contains("(1 row)") ?: false }127 }128 }129 }130 afterSpec {131 // todo: run in parallel132 runBlocking {133 fun delete(instance: Instance) = async {134 if (Instance.describe(instance, maybeServiceAccount).isSuccess) {135 Instance.delete(instance, maybeServiceAccount)136 }137 }138 val i1 = delete(instance1)139 val i2 = delete(instance2)140 val i3 = delete(instance3)141 val i4 = delete(instance4)142 val i5 = delete(instance5)143 val i6 = delete(instance6)144 i1.await()145 i2.await()146 i3.await()147 i4.await()148 i5.await()149 i6.await()150 }151 }152})...

Full Screen

Full Screen

helloSpec.kt

Source:helloSpec.kt Github

copy

Full Screen

1package playground2import io.kotest.assertions.print.print3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.assertions.withClue5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.matchers.Matcher7import io.kotest.matchers.MatcherResult8import io.kotest.matchers.shouldBe9import io.kotest.matchers.shouldNot10import io.kotest.matchers.throwable.shouldHaveMessage11import java.time.LocalDate12class HelloSpec : DescribeSpec({13 describe("hello") {14 it("should compare strings") {15 // given:16 val name = "planet"17 // when/then:18 "hello, $name!".shouldBe("hello, world!")19 }20 it("should have a clue and compare strings") {21 withClue("should be string '1'") {22 1.shouldBe("1")23 }24 }25 it("should have exception assertion") {26 shouldThrow<IllegalStateException> {27 error("error message")28 }.shouldHaveMessage("error message")29 }30 it("should format values for assertion error messages") {31 println(1.print())32 println("1".print())33 println(true.print())34 println(null.print())35 println("".print())36 println(listOf(1, 2, 3).print())37 println(listOf(1, 2, listOf(3, 4, listOf(5, 6))).print())38 println(LocalDate.parse("2020-01-02").print())39 data class AvroProduct(val name: String)40 data class Product(val name: String)41 listOf(1, 2).shouldBe(arrayOf(1, 2))42 Product("foo").shouldBe(AvroProduct("foo"))43 }44 it("should use custom matcher") {45 fun containFoo() = object : Matcher<String> {46 override fun test(value: String) = MatcherResult(47 value.contains("foo"),48 { "String '$value' should include 'foo'" },49 { "String '$value' should not include 'foo'" }50 )51 }52 "hello foo".shouldNot(containFoo())53 "hello bar".shouldNot(containFoo())54 }55 }56})57/*58use soft assertions to group assertions.59```60assertSoftly(foo) {61 shouldNotEndWith("b")62 length.shouldBe(3)63}64custom matchers65```66interface Matcher<in T> {67 fun test(value: T): MatcherResult68}69```70*/...

Full Screen

Full Screen

MatcherTest.kt

Source:MatcherTest.kt Github

copy

Full Screen

...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

EShopProductRootTest.kt

Source:EShopProductRootTest.kt Github

copy

Full Screen

1package io.github.servb.eShop.product2import io.github.servb.eShop.util.kotest.jsonKeyValueEntries3import io.github.servb.eShop.util.kotest.shouldContainExactly4import io.github.servb.eShop.util.kotest.shouldContainJsonKeyAndValueOfSpecificType5import io.github.servb.eShop.util.kotest.shouldContainJsonKeyValue6import io.kotest.core.spec.style.BehaviorSpec7import io.kotest.data.blocking.forAll8import io.kotest.data.row9import io.kotest.matchers.shouldBe10import io.kotest.matchers.string.shouldBeInteger11import io.kotest.matchers.string.shouldEndWith12import io.ktor.http.HttpMethod13import io.ktor.http.HttpStatusCode14import io.ktor.server.testing.handleRequest15class EShopProductRootTest : BehaviorSpec({16 forAll(17 row(AlwaysNoConnectionRequestValidator),18 row(AlwaysFailRequestValidator),19 row(AlwaysSuccessRequestValidator)20 ) { requestValidator ->21 givenTestContainerEShopProduct(requestValidator) { eShopProduct ->22 `when`("I call GET /") {23 val call = eShopProduct.handleRequest(HttpMethod.Get, "/")24 then("the response status should be OK") {25 call.response.status() shouldBe HttpStatusCode.OK26 }27 then("the response body should have proper 'name' and 'uptime' fields") {28 val responseJson = call.response.content29 responseJson shouldContainExactly 2.jsonKeyValueEntries30 responseJson.shouldContainJsonKeyValue("name", "e-shop-product")31 val uptime: String = responseJson shouldContainJsonKeyAndValueOfSpecificType "uptime"32 uptime shouldEndWith "s"33 uptime.dropLast(1).shouldBeInteger()34 }35 }36 }37 }38})...

Full Screen

Full Screen

FunSpecSimpleTest.kt

Source:FunSpecSimpleTest.kt Github

copy

Full Screen

...3import io.kotest.assertions.json.shouldNotEqualJson4import io.kotest.core.spec.style.FunSpec5import io.kotest.matchers.should6import io.kotest.matchers.shouldBe7import io.kotest.matchers.string.endWith8import io.kotest.matchers.string.shouldContain9import io.kotest.matchers.string.startWith10class FunSpecSimpleTest : FunSpec({11 test("name of tester should return the correct length") {12 val nameTester = "Matheus Marin"13 nameTester.shouldContain("Matheus")14 nameTester.length shouldBe 1315 nameTester should startWith("Matheus")16 nameTester should endWith("Marin")17 }18 test("a json with a developer should be valid") {19 val json = """ { "age" : 23, "name": "matheus", "location": "sao paulo" } """20 json.shouldEqualJson(returnJsonOfAValidDev())21 }22 test("a json with a PO should be invalid") {23 val json = """ { "age" : 45, "name": "robert", "location": "rio de janeiro" } """24 json.shouldNotEqualJson(returnJsonOfAValidDev())25 }26}) {27 companion object {28 fun returnJsonOfAValidDev() : String{29 return """ { "age" : 23, "name": "matheus", "location": "sao paulo" } """30 }...

Full Screen

Full Screen

SeatSearchTest.kt

Source:SeatSearchTest.kt Github

copy

Full Screen

...13 }14 test("handle directions") {15 instance.move("F")16 instance.start shouldBeExactly 017 instance.end shouldBeExactly 6318 instance.move("B")19 instance.start shouldBeExactly 3220 instance.end shouldBeExactly 6321 instance.move("F")22 instance.start shouldBeExactly 3223 instance.end shouldBeExactly 4724 instance.move("B")25 instance.move("B")26 instance.move("F")27 instance.move("F")28 instance.start shouldBeExactly 4429 instance.end shouldBeExactly 4430 }31})...

Full Screen

Full Screen

TokenCreatorTest.kt

Source:TokenCreatorTest.kt Github

copy

Full Screen

1package io.github.servb.eShop.auth2import io.github.servb.eShop.auth.util.TokenCreator3import io.github.servb.eShop.util.kotest.*4import io.github.servb.eShop.util.ktor.withTestApplication5import io.kotest.core.spec.style.BehaviorSpec6import io.kotest.core.spec.style.FreeSpec7import io.kotest.matchers.collections.shouldBeUnique8import io.kotest.matchers.shouldBe9import io.kotest.matchers.string.shouldEndWith10import io.kotest.matchers.string.shouldNotBeEmpty11import io.ktor.application.Application12import io.ktor.http.HttpMethod13import io.ktor.http.HttpStatusCode14import io.ktor.server.testing.handleRequest15class TokenCreatorTest : FreeSpec({16 "test token creator" - {17 "generated token should be non-empty" {18 TokenCreator.createToken().shouldNotBeEmpty()19 }20 "generated tokens should be different" {21 val tokens = (1..10000).map { TokenCreator.createToken() }22 tokens.shouldBeUnique()23 }24 }25})...

Full Screen

Full Screen

end

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.string.endWith2import io.kotest.matchers.string.startWith3import io.kotest.matchers.string.shouldBeLowerCase4import io.kotest.matchers.string.shouldBeUpperCase5import io.kotest.matchers.string.shouldContainOnlyDigits6import io.kotest.matchers.string.shouldContainOnlyLetters7import io.kotest.matchers.string.shouldContainOnlyOnce8import io.kotest.matchers.string.shouldContainOnlyOnceIgnoringCase9import io.kotest.matchers.string.shouldContainSame10import io.kotest.matchers.string.shouldHaveLength11import io.kotest.matchers.string.shouldMatch12import io.kotest.matchers.string.shouldNotBeEmpty13import io.kotest.matchers.string.shouldNotBeLowerCase14import io.kotest.matchers.string.shouldNotBeUpperCase15import io.kotest.matchers.string.shouldNotContainOnlyDigits16import io.kotest.matchers.string.shouldNotContainOnlyLetters17import io

Full Screen

Full Screen

end

Using AI Code Generation

copy

Full Screen

1import io.kotst.matches.string.shouldContain2import io.kotest.matchers.string.shouldContain3s MyTet: tringSpec({4 "test" {5 }6})

Full Screen

Full Screen

end

Using AI Code Generation

copy

Full Screen

1class StringMatchers : Matchers {2override fun matchers() = listOf(3Matcher(String::class, "should start with", { this should startWith(it) }),4Matcher(String::class, "should end with", { this should endWith(it) }),5Matcher(String::class, "should contain", { this should contain(it) })6}7class StringMatchersTest : FunSpec({8include(StringMatchers())9test("using string matchers") {10"hello" should startWith("he")11"hello" should endWith("lo")12"hello" should contain("el")13}14})15class StringMatchersTest : FunSpec({16test("using string matchers") {17"hello" should startWith("he")18"hello" should endWith("lo")19"hello" should contain("el")20}21})22class StringMatchers : Matchers {23override fun matchers() = listOf(24Matcher(String::class, "should start with", { this should startWith(it) })25}26class StringMatchersTest : FunSpec({27include(StringMatchers())28test("using string matchers") {29"hello" should startWith("he")30}31})32class StringMatchersTest : FunSpec({33test("using string matchers") {34"hello" should startWith("he")35}36})

Full Screen

Full Screen

end

Using AI Code Generation

copy

Full Screen

1class StringMatchersTest : FunSpec({2test("using string matchers") {3"hello" should startWith("he")4"hello" should endWith("lo")5"hello" should contain("el")6}7})

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 end

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful