Best Kotest code snippet using io.kotest.matchers.nulls.matchers.beNull
CategoryRepositoryCreateSpec.kt
Source:CategoryRepositoryCreateSpec.kt
...3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.ExpectSpec5import io.kotest.matchers.collections.shouldHaveSize6import io.kotest.matchers.collections.singleElement7import io.kotest.matchers.nulls.beNull8import io.kotest.matchers.shouldBe9import io.kotest.matchers.shouldHave10import io.kotest.matchers.shouldNot11import io.kotest.property.Arb12import io.kotest.property.arbitrary.chunked13import io.kotest.property.arbitrary.next14import io.kotest.property.arbitrary.single15import io.kotest.property.arbitrary.string16import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest17import org.springframework.data.jpa.repository.config.EnableJpaAuditing18import javax.validation.ConstraintViolation19import javax.validation.ConstraintViolationException20@EnableJpaAuditing21@DataJpaTest(22 showSql = true,23 properties = [24 "spring.flyway.enabled=false",25 "spring.jpa.hibernate.ddl-auto=create"26 ]27)28class CategoryRepositoryCreateSpec(29 private val categoryRepository: CategoryRepository30) : ExpectSpec() {31 companion object {32 private const val ONE_TO_FIFTY_MESSAGE = "í¬ê¸°ê° 0ìì 50 ì¬ì´ì¬ì¼ í©ëë¤"33 }34 init {35 context("Category ìì±ì í ë") {36 val targetCategory = Mock.category().single()37 expect("Nameë§ ìì¼ë©´ Categoryê° ìì±ëë¤.") {38 val savedCategory = categoryRepository.save(targetCategory)39 savedCategory.id shouldNot beNull()40 savedCategory.name shouldBe targetCategory.name41 }42 expect("Nameì´ ë¹ì´ìì´ë Categoryê° ìì±ëë¤.") {43 targetCategory.name = ""44 val savedCategory = categoryRepository.save(targetCategory)45 savedCategory.id shouldNot beNull()46 savedCategory.name shouldBe targetCategory.name47 }48 expect("Nameê³¼ íì Category ì ë³´ë¡ Categoryê° ìì±ëë¤.") {49 val categoryChildren = Mock.category().chunked(10, 10).single()50 targetCategory.children = categoryChildren51 val savedCategory = categoryRepository.save(targetCategory)52 savedCategory.id shouldNot beNull()53 savedCategory.name shouldBe targetCategory.name54 savedCategory.children shouldNot beNull()55 savedCategory.children!! shouldHaveSize categoryChildren.size56 }57 expect("Nameê³¼ 2Depthì íì Categoriesë¡ Categoryê° ìì±ëë¤.") {58 val childrenOfChildrenOfChildren = Mock.category().chunked(10, 10).single()59 val childrenOfChildren = Mock.category(children = childrenOfChildrenOfChildren).chunked(10, 10).single()60 val categoryChildren = Mock.category(children = childrenOfChildren).chunked(20, 20).single()61 targetCategory.children = categoryChildren62 val savedCategory = categoryRepository.save(targetCategory)63 savedCategory.id shouldNot beNull()64 savedCategory.name shouldBe targetCategory.name65 savedCategory.children shouldNot beNull()66 savedCategory.children!! shouldHaveSize categoryChildren.size67 savedCategory.children!!.forEach { children ->68 children.children shouldNot beNull()69 children.children!! shouldHaveSize childrenOfChildren.size70 children.children!!.forEach { childrenOfChildren ->71 childrenOfChildren.children shouldNot beNull()72 childrenOfChildren.children!! shouldHaveSize childrenOfChildrenOfChildren.size73 }74 }75 }76 expect("Nameì´ ìê³ì¹ë¥¼ ì´ê³¼íë©´ Category를 ìì±í ì ìë¤.") {77 val nameThreshold = 5178 targetCategory.name = Arb.string(nameThreshold, nameThreshold).next()79 val constraintViolationException = shouldThrow<ConstraintViolationException> {80 categoryRepository.save(targetCategory)81 }82 constraintViolationException.constraintViolations shouldHave83 singleElement {84 isEqualCheckOneToFiftyMessage(it) && isEqualTestName(it, targetCategory)85 }...
JsonSourceTest.kt
Source:JsonSourceTest.kt
2import com.fasterxml.jackson.jr.ob.JSON3import dev.madetobuild.typedconfig.runtime.key.SimpleKey4import io.kotest.assertions.throwables.shouldThrow5import io.kotest.matchers.doubles.plusOrMinus6import io.kotest.matchers.nulls.beNull7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import org.junit.jupiter.api.Test10import java.nio.file.Files11class JsonSourceTest {12 private val source = JsonSource(13 mapOf(14 "foo" to 1,15 "bar" to mapOf("baz" to 2),16 // lists don't make sense here17 "list" to listOf(3),18 "str" to "foo",19 "double" to 1.23,20 "boolean" to true,21 )22 )23 @Test24 fun intTopLevelKey() {25 source.getInt(SimpleKey("foo")) shouldBe 126 }27 @Test28 fun intMissingTopLevelKey() {29 source.getInt(SimpleKey("missing")) should beNull()30 }31 @Test32 fun intNestedKey() {33 source.getInt(SimpleKey("bar.baz")) shouldBe 234 }35 @Test36 fun intNestedKeyObject() {37 source.getInt(SimpleKey("bar")) should beNull()38 }39 @Test40 fun intNestedKeyList() {41 source.getInt(SimpleKey("list.1")) should beNull()42 }43 @Test44 fun stringKey() {45 source.getString(SimpleKey("str")) shouldBe "foo"46 source.getString(SimpleKey("foo")) shouldBe null47 }48 @Test49 fun doubleKey() {50 source.getDouble(SimpleKey("double")) shouldBe (1.23 plusOrMinus 0.01)51 source.getDouble(SimpleKey("foo")) shouldBe null52 }53 @Test54 fun booleanKey() {55 source.getBoolean(SimpleKey("boolean")) shouldBe true...
FormatFileTest.kt
Source:FormatFileTest.kt
...3import io.kotest.core.spec.style.WordSpec4import io.kotest.core.spec.tempfile5import io.kotest.matchers.and6import io.kotest.matchers.collections.beEmpty7import io.kotest.matchers.nulls.beNull8import io.kotest.matchers.paths.aFile9import io.kotest.matchers.paths.beReadable10import io.kotest.matchers.paths.exist11import io.kotest.matchers.should12import io.kotest.matchers.shouldNot13import java.io.File14import java.nio.file.Files15import java.nio.file.Path16import java.nio.file.Paths17import java.nio.file.StandardCopyOption18class FormatFileTest : WordSpec() {19 companion object {20 val LINE_SEPARATOR = System.getProperty("line.separator") ?: "\n";21 }22 private lateinit var actual: File23 private fun resourcePath(name: String): Path {24 val path = this.javaClass.getResource(name)?.let {25 Paths.get(it.file)26 }27 path shouldNot beNull()28 path!! should (exist() and aFile() and beReadable())29 return path.normalize()30 }31 init {32 beforeTest {33 actual = tempfile("format-test")34 }35 "eclipselink result file" should {36 "be formatted" {37 val source = resourcePath("/eclipselink-normal-result.txt")38 val expected = resourcePath("/eclipselink-format-result.txt")39 val actualPath = actual.toPath()40 Files.copy(source, actualPath, StandardCopyOption.REPLACE_EXISTING)41 formatFile(actualPath, true, LINE_SEPARATOR)...
CategoryRepositorySelectSpec.kt
Source:CategoryRepositorySelectSpec.kt
2import 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" {27 val targetCategory = Mock.category().single()28 val savedCategory = categoryRepository.save(targetCategory)29 val savedCategoryId = savedCategory.id ?: throw IllegalArgumentException()30 val foundCategories = categoryRepository.findAll()31 foundCategories shouldHaveSize 132 foundCategories shouldHave singleElement { it.id == savedCategoryId }33 }34 "ID를 íµí Category ì¡°í ì±ê³µ Test" {35 val categoryChildren = Mock.category().chunked(10, 10).single()36 val targetCategory = Mock.category(children = categoryChildren).single()37 val savedCategory = categoryRepository.save(targetCategory)38 val savedCategoryId = savedCategory.id ?: throw IllegalArgumentException()39 val foundCategory = categoryRepository.findById(savedCategoryId).get()40 foundCategory.name shouldBe savedCategory.name41 foundCategory.children shouldNot beNull()42 foundCategory.children!!.map { it.name } shouldBe43 targetCategory.children!!.map { it.name }44 }45 }46}...
TestEffectLoading.kt
Source:TestEffectLoading.kt
...12import io.kotest.engine.spec.tempfile13import io.kotest.matchers.file.shouldBeAFile14import io.kotest.matchers.file.shouldExist15import io.kotest.matchers.file.shouldNotBeEmpty16import io.kotest.matchers.nulls.beNull17import io.kotest.matchers.nulls.shouldNotBeNull18import io.kotest.matchers.shouldBe19import io.kotest.matchers.shouldNot20import it.unibo.alchemist.boundary.gui.effects.DrawBidimensionalGaussianLayersGradient21import it.unibo.alchemist.boundary.gui.effects.EffectSerializationFactory22import org.kaikikm.threadresloader.ResourceLoader23import java.io.File24class TestEffectLoading : StringSpec(25 {26 "effects with layers should be (de)serializable" {27 val target = DrawBidimensionalGaussianLayersGradient()28 val tempFile = tempfile()29 EffectSerializationFactory.effectToFile(tempFile, target)30 println(tempFile.readText())31 tempFile.shouldExist()32 tempFile.shouldBeAFile()33 tempFile.shouldNotBeEmpty()34 EffectSerializationFactory.effectsFromFile(tempFile).shouldNotBeNull()35 }36 "legacy effects with layers should be deserializable" {37 val target = ResourceLoader.getResource("layer.json")38 target shouldNot beNull()39 val file = File(target.file)40 file.shouldExist()41 file.shouldNotBeEmpty()42 file.shouldBeAFile()43 val effects = EffectSerializationFactory.effectsFromFile(file)44 effects.shouldNotBeNull()45 effects.size shouldBe 446 }47 }48)...
TestWebsiteCodeSnippets.kt
Source:TestWebsiteCodeSnippets.kt
1import io.kotest.core.spec.style.FreeSpec2import io.kotest.matchers.collections.beEmpty3import io.kotest.matchers.collections.shouldBeEmpty4import io.kotest.matchers.collections.shouldNotBeEmpty5import io.kotest.matchers.nulls.beNull6import io.kotest.matchers.nulls.shouldNotBeNull7import io.kotest.matchers.shouldNot8import it.unibo.alchemist.util.ClassPathScanner9import it.unibo.alchemist.core.implementations.Engine10import it.unibo.alchemist.loader.LoadAlchemist11/*12 * Copyright (C) 2010-2021, Danilo Pianini and contributors13 * listed in the main project's alchemist/build.gradle.kts file.14 *15 * This file is part of Alchemist, and is distributed under the terms of the16 * GNU General Public License, with a linking exception,17 * as described in the file LICENSE in the Alchemist distribution's top directory.18 */19class TestWebsiteCodeSnippets : FreeSpec(20 {21 val allSpecs = ClassPathScanner.resourcesMatching(".*", "website-snippets")22 .also { it shouldNot beEmpty() }23 .onEach { it shouldNot beNull() }24 allSpecs.forEach { url ->25 "snippet ${url.path.split("/").last()} should load correctly" - {26 val environment = LoadAlchemist.from(url).getDefault<Any, Nothing>().environment27 environment.shouldNotBeNull()28 if (url.readText().contains("deployments:")) {29 "and have deployed nodes" {30 environment.shouldNotBeEmpty()31 environment.nodes shouldNot beEmpty()32 }33 } else {34 "and be empty" {35 environment.shouldBeEmpty()36 }37 }...
ClientTypeStoreTest.kt
Source:ClientTypeStoreTest.kt
1package com.rp199.aws.restclient.store2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.nulls.beNull4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6internal class ClientTypeStoreTest : StringSpec({7 "getClientType should relate to each thread"{8 ClientTypeStore.setClientType(ClientType.AWS)9 val thread1 = Thread {10 ClientTypeStore.setClientType(ClientType.LOCAL)11 }12 thread1.start()13 thread1.join()14 ClientTypeStore.getClientType() shouldBe ClientType.AWS15 }16 "clear should remove clientType from the store" {17 ClientTypeStore.setClientType(ClientType.LOCAL)18 ClientTypeStore.getClientType() shouldBe ClientType.LOCAL19 ClientTypeStore.clear()20 ClientTypeStore.getClientType() should beNull()21 }22})...
AnnotationsTest.kt
Source:AnnotationsTest.kt
1package dev.madetobuild.typedconfig.test2import dev.madetobuild.typedconfig.runtime.Key3import io.kotest.matchers.collections.beEmpty4import io.kotest.matchers.nulls.beNull5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNot7import org.junit.jupiter.api.Test8import kotlin.reflect.full.findAnnotation9class AnnotationsTest {10 @Test11 fun topLevelKeys() {12 GeneratedConfig::maxLoginTries.annotations shouldNot beEmpty()13 val annotation = GeneratedConfig::maxLoginTries.findAnnotation<Key>()14 annotation shouldNot beNull()15 annotation?.name shouldBe "maxLoginTries"16 }17 @Test18 fun nestedKeys() {19 val annotation = NestedConfig.Database::port.findAnnotation<Key>()20 annotation shouldNot beNull()21 annotation?.name shouldBe "database.port"22 }23}...
beNull
Using AI Code Generation
1 "be null" {2 nullValue should beNull()3 }4 "not be null" {5 nullValue shouldNot beNotNull()6 }7 }8}
beNull
Using AI Code Generation
1 val emptyList = listOf<Int>()2 emptyList shouldBe emptyList<Int>()3 val list = listOf<Int>(1, 2, 3)4 list should contain(1)5 list should contain(1, 2, 3)6 list should contain(1, 3)7 list should contain(1, 3, 2)8 list should contain(2, 1, 3)9 list should contain(2, 3, 1)10 list should contain(3, 1, 2)11 list should contain(3, 2, 1)12 "abc" should beOneOf("abc", "def", "ghi")13 1 should beOneOf(1, 2, 3)14 1.0 should beOneOf(1.0, 2.0, 3.0)15 1.0f should beOneOf(1.0f, 2.0f, 3.0f)16 1L should beOneOf(1L, 2L, 3L)17 1.toByte() should beOneOf(1.toByte(), 2.toByte(), 3.toByte())
beNull
Using AI Code Generation
1 expect(null).toBeNull()2 }3}4class MatchersTest : FunSpec() {5 init {6 expect(true).toBeTrue()7 }8}9class MatchersTest : FunSpec() {10 init {11 expect(true).toBeTruthy()12 }13}14class MatchersTest : FunSpec() {15 init {16 expect(1).toBeValid()17 }18}19class MatchersTest : FunSpec() {20 init {21 expect(0).toBeZero()22 }23}24class MatchersTest : FunSpec() {25 init {26 expect(listOf(1, 2, 3)).toContain(1)27 }28}29class MatchersTest : FunSpec() {30 init {31 expect(listOf(1, 2, 3)).toContainAll(1, 2)32 }33}34class MatchersTest : FunSpec() {35 init {36 expect(listOf(1, 2, 3)).toContainExactly(1, 2, 3)37 }38}39class MatchersTest : FunSpec() {40 init {41 expect(listOf(1, 2, 3)).toContainExactlyInAnyOrder(1, 2,
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!