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

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

ServerTest.kt

Source:ServerTest.kt Github

copy

Full Screen

...21 * SOFTWARE.22 *23 */24package ttgamelib.net25import io.kotest.core.spec.style.FunSpec26import io.kotest.data.forAll27import io.kotest.data.row28import io.kotest.inspectors.forAll29import io.kotest.matchers.booleans.shouldBeFalse30import io.kotest.matchers.booleans.shouldBeTrue31import io.kotest.matchers.collections.shouldBeEmpty32import io.kotest.matchers.collections.shouldContain33import io.kotest.matchers.collections.shouldHaveSize34import io.kotest.matchers.maps.shouldContainValue35import io.kotest.matchers.shouldBe36import io.kotest.matchers.shouldNotBe37import io.kotest.matchers.types.shouldBeInstanceOf38import io.kotest.matchers.types.shouldBeTypeOf39import io.ktor.http.cio.websocket.*40import io.mockk.*41import kotlinx.serialization.json.Json42import ttgamelib.GameEngine43private inline fun<reified T: Packet> List<Frame>.decode(): List<T> {44 return map {45 Json.decodeFromString(Packet.serializer(), (it as Frame.Text).readText()) as T46 }47}48private fun createConnection(userName: String, clientId: Int): Pair<ClientConnection, MutableList<Frame>> {49 val sentPackets = mutableListOf<Frame>()50 val session = mockk<DefaultWebSocketSession>().also {51 coEvery {52 it.send(capture(sentPackets))53 } just Runs54 }55 val connection = ClientConnection(session).apply {56 name = userName57 id = clientId58 }59 return connection to sentPackets60}61internal class ServerTest : FunSpec({62 val engine = mockk<GameEngine>(relaxed = true)63 val (connection, sentPackets) = createConnection("player1", 1)64 lateinit var server: Server65 beforeEach {66 sentPackets.clear()67 }68 context("SendNamePacket") {69 val userName = "New User"70 server = Server("localhost", 1000, engine)71 test("should create new user if name is not in use") {72 server.handlePacket(SendNamePacket(userName), connection)73 val sent = sentPackets.decode<Packet>()74 sent[0].shouldBeInstanceOf<InitClientPacket>()75 (sent[0] as InitClientPacket).clientId shouldBe connection.id76 sent[1].shouldBeInstanceOf<ChatMessagePacket>()77 coVerify {78 engine.playerConnected(connection.id, userName)79 }80 }81 test("should request another name if in use") {82 val (connection2, sentPackets2) = createConnection("player2", 2)83 server.handlePacket(SendNamePacket(userName), connection2)84 val sent = sentPackets2.decode<SuggestNamePacket>()85 with (sent[0]) {86 name shouldNotBe userName87 taken.shouldContain(userName)88 disconnected.shouldBeFalse()89 }90 }91 test("should check for reconnection if disconnected") {92 server.connections.remove(connection.id)93 server.handlePacket(SendNamePacket(userName), connection)94 val sent = sentPackets.decode<SuggestNamePacket>()95 with (sent[0]) {96 name shouldNotBe userName97 taken.shouldContain(userName)98 disconnected.shouldBeTrue()99 }100 }101 test("should replace player on reconnection") {102 server.handlePacket(SendNamePacket(userName, true), connection)103 val sent = sentPackets.decode<Packet>()104 sent[0].shouldBeInstanceOf<InitClientPacket>()105 (sent[0] as InitClientPacket).clientId shouldBe connection.id106 sent[1].shouldBeInstanceOf<ChatMessagePacket>()107 coVerify {108 engine.playerReconnected(connection.id)109 }110 }111 test("should not replace player that is connected") {112 server.handlePacket(SendNamePacket(userName, true), connection)113 val sent = sentPackets.decode<SuggestNamePacket>()114 with (sent[0]) {115 name shouldNotBe userName116 disconnected.shouldBeFalse()117 }118 }119 }120 test("GameCommandPacket should be sent to game engine") {121 val packet = MessagePacket(object : GameMessage{})122 server.handlePacket(packet, connection)123 sentPackets.shouldBeEmpty()124 coVerify {125 engine.handle(connection.id, packet)126 }127 }128 context("chat command") {129 server = Server("localhost", 1000, engine)130 val connections = mutableListOf<ClientConnection>()131 val outgoing = mutableListOf<MutableList<Frame>>()132 for (i in 1..3) {133 with (createConnection("player$i", i)) {134 connections += first135 outgoing += second136 server.handlePacket(SendNamePacket(first.name), first)137 }138 }139 beforeEach {140 outgoing.forEach { it.clear() }141 }142 test("there should be three connected players") {143 connections.forAll {144 server.connections.shouldContainValue(it)145 }146 }147 test("emote should send message to all users") {148 forAll(149 row("/em is here"),150 row("/me is here")151 ) { msg ->152 server.handlePacket(ChatCommandPacket(connection.id, msg), connection)153 }154 outgoing.forEach {155 with (it.decode<ChatMessagePacket>()) {156 shouldHaveSize(2)157 forAll { it.message.shouldBeTypeOf<EmoteMessage>() }158 }159 }160 }161 test("whisper should send message to one user") {162 server.handlePacket(ChatCommandPacket(connections[0].id, "/w player2 a secret"), connections[0])163 outgoing[0].shouldHaveSize(1)164 outgoing[1].shouldHaveSize(1)165 outgoing[2].shouldBeEmpty()166 }167 test("whisper to unknown user should send info message to sender") {168 server.handlePacket(ChatCommandPacket(connections[1].id, "/w nobody a secret"), connections[1])169 outgoing[0].shouldHaveSize(0)170 outgoing[2].shouldHaveSize(0)171 outgoing[1].shouldHaveSize(1)172 outgoing[1].decode<ChatMessagePacket>().forAll {173 it.message.shouldBeTypeOf<InfoMessage>()174 }175 }176 test("unknown command should send info message to sender") {177 server.handlePacket(ChatCommandPacket(connections[1].id, "/foo bar baz"), connections[1])178 outgoing[0].shouldHaveSize(0)179 outgoing[2].shouldHaveSize(0)180 outgoing[1].shouldHaveSize(1)181 outgoing[1].decode<ChatMessagePacket>().forAll {182 it.message.shouldBeTypeOf<InfoMessage>()183 }184 }185 }186})...

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

VendedorTest.kt

Source:VendedorTest.kt Github

copy

Full Screen

1package ar.edu.unahur.obj2.vendedores2import io.kotest.assertions.throwables.shouldThrowAny3import io.kotest.core.spec.style.DescribeSpec4import io.kotest.matchers.booleans.shouldBeFalse5import io.kotest.matchers.booleans.shouldBeTrue6import io.kotest.matchers.collections.shouldContain7import io.kotest.matchers.collections.shouldContainAll8import io.kotest.matchers.collections.shouldNotContain9import io.kotest.matchers.should10import io.kotest.matchers.shouldBe11class ComercioTest : DescribeSpec({12 val buenosAires = Provincia(15000000)13 val santaFe = Provincia(9000000)14 val cordoba = Provincia(12000000)15 val entreRios = Provincia(1500000)16 val chivilcoy = Ciudad(buenosAires)17 val bragado = Ciudad(buenosAires)18 val lobos = Ciudad(buenosAires)19 val pergamino = Ciudad(buenosAires)20 val zarate = Ciudad(buenosAires)21 val rosario = Ciudad(santaFe)22 val rafaela = Ciudad(santaFe)23 val sanFrancisco = Ciudad(cordoba)24 val diamante = Ciudad(entreRios)...

Full Screen

Full Screen

InMemoryHopRepositoryTest.kt

Source:InMemoryHopRepositoryTest.kt Github

copy

Full Screen

...4import 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"...

Full Screen

Full Screen

LibraryRepositoryTest.kt

Source:LibraryRepositoryTest.kt Github

copy

Full Screen

2import com.noto.app.util.repositoryModule3import com.noto.app.domain.model.Library4import com.noto.app.domain.repository.LibraryRepository5import com.noto.app.fakeLocalDataSourceModule6import io.kotest.core.spec.style.StringSpec7import io.kotest.matchers.collections.shouldBeEmpty8import io.kotest.matchers.collections.shouldContain9import io.kotest.matchers.collections.shouldHaveSize10import io.kotest.matchers.collections.shouldNotBeEmpty11import io.kotest.matchers.string.shouldBeEqualIgnoringCase12import kotlinx.coroutines.flow.single13import org.koin.core.context.startKoin14import org.koin.core.context.stopKoin15import org.koin.test.KoinTest16import org.koin.test.get17class LibraryRepositoryTest : StringSpec(), KoinTest {18 private lateinit var repository: LibraryRepository19 init {20 beforeTest {21 startKoin {22 modules(fakeLocalDataSourceModule, repositoryModule)23 }24 repository = get()25 }26 afterTest {27 stopKoin()28 }29 "get all libraries should be empty" {30 repository.getLibraries()...

Full Screen

Full Screen

CategoryRepositorySelectSpec.kt

Source:CategoryRepositorySelectSpec.kt Github

copy

Full Screen

1package com.gaveship.category.domain.model2import com.gaveship.category.Mock3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.collections.shouldHaveSize5import io.kotest.matchers.collections.singleElement6import io.kotest.matchers.nulls.beNull7import io.kotest.matchers.shouldBe8import io.kotest.matchers.shouldHave9import io.kotest.matchers.shouldNot10import io.kotest.property.arbitrary.chunked11import io.kotest.property.arbitrary.single12import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest13import org.springframework.data.jpa.repository.config.EnableJpaAuditing14@EnableJpaAuditing15@DataJpaTest(16 showSql = true,17 properties = [18 "spring.flyway.enabled=false",19 "spring.jpa.hibernate.ddl-auto=create"20 ]21)22class CategoryRepositorySelectSpec(23 private val categoryRepository: CategoryRepository24) : StringSpec() {25 init {26 "Root Categories 조회 성공 Test" {...

Full Screen

Full Screen

KoTestTest.kt

Source:KoTestTest.kt Github

copy

Full Screen

1package com.example.testingcomparison2import io.kotest.assertions.assertSoftly3import io.kotest.matchers.Matcher4import io.kotest.matchers.MatcherResult5import io.kotest.matchers.collections.shouldContain6import io.kotest.matchers.collections.shouldHaveSize7import io.kotest.matchers.collections.shouldNotContain8import io.kotest.matchers.should9import io.kotest.matchers.types.shouldBeInstanceOf10import org.junit.Test11class 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

test

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3)2list.shouldContain(2)3val list = listOf(1, 2, 3)4list.shouldNotContain(4)5val list = listOf(1, 2, 3)6list.shouldContainAll(1, 2)7val list = listOf(1, 2, 3)8list.shouldNotContainAll(4, 5)9val list = listOf(1, 2, 3)10list.shouldContainExactly(1, 2, 3)11val list = listOf(1, 2, 3)12list.shouldNotContainExactly(1, 2, 3, 4)13val list = listOf(1, 2, 3)14list.shouldContainInOrder(1, 2)15val list = listOf(1, 2, 3)16list.shouldContainInOrderOnly(1, 2, 3)17val list = listOf(1, 2, 3)18list.shouldContainNone(4, 5)19val list = listOf(1, 2, 3)20list.shouldContainSame(listOf(1, 2, 3))21val list = listOf(1, 2, 3)22list.shouldHaveAtLeastSize(1)23val list = listOf(1, 2, 3)24list.shouldHaveAtMostSize(3)

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.collections.matchers2assertThat(listOf(1, 2, 3)).matches(listOf(1, 2, 3))3import io.kotest.matchers.collections.should4listOf(1, 2, 3) should match(listOf(1, 2, 3))5import io.kotest.matchers.collections.shouldNot6listOf(1, 2, 3) shouldNot match(listOf(1, 2, 3))7import io.kotest.matchers.collections.shouldBe8listOf(1, 2, 3) shouldBe match(listOf(1, 2, 3))9import io.kotest.matchers.collections.shouldNotBe10listOf(1, 2, 3) shouldNotBe match(listOf(1, 2, 3))11import io.kotest.matchers.collections.shouldContain12listOf(1, 2, 3) shouldContain match(listOf(1, 2, 3))13import io.kotest.matchers.collections.shouldNotContain14listOf(1, 2, 3) shouldNotContain match(listOf(1, 2, 3))15import io.kotest.matchers.collections.shouldContainAll16listOf(1, 2, 3) shouldContainAll match(listOf(1, 2, 3))17import io.kotest.matchers.collections.shouldNotContainAll18listOf(1, 2, 3) shouldNotContainAll match(listOf(1, 2, 3))

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" ))2assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "three" , "two" ))3assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" ))4assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))5assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))6assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))7assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))8assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))9assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))10assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))11assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))12assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))13assertThat (listOf ( "one" , "two" , "three" ), containsInOrder ( "one" , "two" , "three" , "four" ))14assertThat (listOf ( "one" , "two" , "three" ), containsIn

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3)2list should contain(2)3list shouldNot contain(4)4val list = listOf(1, 2, 3)5list should contain(2)6list shouldNot contain(4)7val list = listOf(1, 2, 3)8list should contain(2)9list shouldNot contain(4)10val list = listOf(1, 2, 3)11list should contain(2)12list shouldNot contain(4)13val list = listOf(1, 2, 3)14list should contain(2)15list shouldNot contain(4)16val list = listOf(1, 2, 3)17list should contain(2)18list shouldNot contain(4)19val list = listOf(1, 2, 3)20list should contain(2)21list shouldNot contain(4)22val list = listOf(1, 2, 3)23list should contain(2)24list shouldNot contain(4)25val list = listOf(1, 2, 3)26list should contain(2)27list shouldNot contain(4)28val list = listOf(1, 2, 3)29list should contain(2)30list shouldNot contain(4)31val list = listOf(1, 2, 3)32list should contain(2)33list shouldNot contain(4)34val list = listOf(1, 2, 3)

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3)2list should haveSize(3)3list should haveSize(2)4list should haveSize(1)5list should haveSize(0)6str should haveLength(11)7str should haveLength(10)8str should haveLength(9)9str should haveLength(8)101 should beGreaterThan(0)111 should beGreaterThan(1)121 should beGreaterThan(2)131 should beGreaterThan(3)141 should beGreaterThan(4)151 should beGreaterThan(5)161 should beGreaterThan(6)171 should beGreaterThan(7)181 should beGreaterThan(8)191 should beGreaterThan(9)201 should beGreaterThan(10)21true should beTrue()22false should beFalse()231.0 should beGreaterThan(0.0)241.0 should beGreaterThan(1.0)251.0 should beGreaterThan(2.0)261.0 should beGreaterThan(3.0)271.0 should beGreaterThan(4.0)281.0 should beGreaterThan(5.0)291.0 should beGreaterThan(6.0)301.0 should beGreaterThan(7.0)311.0 should beGreaterThan(8.0)321.0 should beGreaterThan(9.0)331.0 should beGreaterThan(10.0)341.0f should beGreaterThan(0.0f)351.0f should beGreaterThan(1.0f)361.0f should beGreaterThan(2.0f)371.0f should beGreaterThan(3.0f)381.0f should beGreaterThan(4.0f)391.0f should beGreaterThan(5.0f)401.0f should beGreaterThan(6.0f)411.0f should beGreaterThan(7.0f)421.0f should beGreaterThan(8.0f)

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.collections.shouldContainAll2 fun main() {3 val list = listOf(1, 2, 3)4 }5 import io.kotest.matchers.collections.shouldContainAll6 fun main() {7 val list = listOf(1, 2, 3)8 }9 import io.kotest.matchers.collections.shouldContainAll10 fun main() {11 val list = listOf(1, 2, 3)

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