How to use Spec class of io.kotest.core.spec package

Best Kotest code snippet using io.kotest.core.spec.Spec

Dependencies.kt

Source:Dependencies.kt Github

copy

Full Screen

1import org.gradle.api.plugins.ObjectConfigurationAction2import org.gradle.kotlin.dsl.DependencyHandlerScope3import org.gradle.kotlin.dsl.ScriptHandlerScope4import org.gradle.kotlin.dsl.exclude5import org.gradle.plugin.use.PluginDependenciesSpec6object Versions {7 // Branch targets for internal deps8 const val Master = "master-+"9 const val Develop = "develop-+"10 const val ProvenanceCore = Master11 const val StreamData = Master12 const val Kotlin = "1.6.21"13 const val KotlinCoroutines = "1.6.1"14 const val Protobuf = "3.18.1"15 const val SpringBoot = "2.5.6"16 const val KotlinLogging = "2.0.11"17 const val Reactor = "3.4.9"18 const val Jackson = "2.12.5"19 const val Redisson = "3.16.0"20 const val Ktlint = "0.45.2"21 const val Detekt = "1.18.1"22 const val Hamkrest = "1.8.0.1"23 const val Mockk = "1.12.0"24 const val Kotest = "5.2.+"25 const val KotestExtensionsArrow = "1.2.+"26 const val KotestCoroutines = "1.6.1"27 const val KotestSpring = "1.1.1"28 const val KotlinFaker = "1.7.1"29 const val SpringMockk = "3.0.1"30 const val Swagger = "1.6.2"31 const val AssetModel = "0.1.7"32 const val P8eScope = "0.6.0"33 const val ProvenanceHdWallet = "0.1.15"34 const val ProvenanceClient = "1.1.1"35 const val Unirest = "3.13.6"36 const val KeyAccessLib = "0.2.17"37 const val LoanPackage = "0.1.16"38 const val Grpc = "1.45.0"39 const val ProvenanceProto = "1.8.0"40 const val Reflections = "0.9.10"41 const val NexusPublishing = "1.1.0"42 const val BouncyCastle = "1.70"43 const val OpenApi = "1.5.13"44 const val TestContainer = "1.3.3"45}46object Plugins { // please keep this sorted in sections47 // Kotlin48 val Kotlin = PluginSpec("kotlin", Versions.Kotlin)49 // 3rd Party50 val Detekt = PluginSpec("io.gitlab.arturbosch.detekt", Versions.Detekt)51 val Idea = PluginSpec("idea")52 val Protobuf = PluginSpec("com.google.protobuf", "0.8.16")53 val SpringBoot = PluginSpec("org.springframework.boot", Versions.SpringBoot)54 val SpringDependencyManagement = PluginSpec("io.spring.dependency-management", "1.0.11.RELEASE")55 val NexusPublishing = PluginSpec("io.github.gradle-nexus.publish-plugin", Versions.NexusPublishing)56}57object Dependencies {58 object OpenApi {59 val WebFluxSupport = DependencySpec("org.springdoc:springdoc-openapi-webflux-ui", Versions.OpenApi)60 val KotlinSupport = DependencySpec("org.springdoc:springdoc-openapi-kotlin", Versions.OpenApi)61 }62 // Kotlin63 object Kotlin {64 val AllOpen = DependencySpec("org.jetbrains.kotlin:kotlin-allopen", Versions.Kotlin)65 val Reflect = DependencySpec("org.jetbrains.kotlin:kotlin-reflect", Versions.Kotlin)66 val StdlbJdk8 = DependencySpec("org.jetbrains.kotlin:kotlin-stdlib-jdk8", Versions.Kotlin)67 val StdlbCommon = DependencySpec("org.jetbrains.kotlin:kotlin-stdlib-common", Versions.Kotlin)68 val CoroutinesCoreJvm = DependencySpec(69 "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm",70 Versions.KotlinCoroutines71 )72 val CoroutinesReactor = DependencySpec(73 "org.jetbrains.kotlinx:kotlinx-coroutines-reactor",74 Versions.KotlinCoroutines75 )76 val CoroutinesJdk8 = DependencySpec(77 "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8",78 Versions.KotlinCoroutines79 )80 val CoroutinesTest = DependencySpec(81 "org.jetbrains.kotlinx:kotlinx-coroutines-test",82 Versions.KotlinCoroutines83 )84 }85 object P8eScope {86 val Encryption = DependencySpec("io.provenance.scope:encryption", Versions.P8eScope)87 val OsClient = DependencySpec("io.provenance.scope:os-client", Versions.P8eScope)88 val Sdk = DependencySpec("io.provenance.scope:sdk", Versions.P8eScope)89 val Util = DependencySpec("io.provenance.scope:util", Versions.P8eScope)90 val ContractBase = DependencySpec("io.provenance.scope:contract-base", Versions.P8eScope)91 val ContractProto = DependencySpec("io.provenance.scope:contract-proto", Versions.P8eScope)92 }93 // Spring Boot94 object SpringBoot {95 val Starter = DependencySpec("org.springframework.boot:spring-boot-starter")96 val StarterWebFlux = DependencySpec(97 name = "org.springframework.boot:spring-boot-starter-webflux",98 exclude = listOf("org.springframework.boot:spring-boot-starter-tomcat")99 )100 val StarterJetty = DependencySpec("org.springframework.boot:spring-boot-starter-jetty")101 val StarterActuator = DependencySpec("org.springframework.boot:spring-boot-starter-actuator")102 val StarterDevTools = DependencySpec("org.springframework.boot:spring-boot-devtools")103 val StarterSecurity = DependencySpec("org.springframework.boot:spring-boot-starter-security")104 val StarterValidation = DependencySpec("org.springframework.boot:spring-boot-starter-validation")105 val Swagger = DependencySpec( "io.springfox:springfox-boot-starter", "3.0.0")106 val SwaggerUI = DependencySpec( "io.springfox:springfox-swagger-ui", "3.0.0")107 val StarterTest =108 DependencySpec(109 name = "org.springframework.boot:spring-boot-starter-test",110 exclude = listOf(111 "org.junit.vintage:junit-vintage-engine",112 "org.mockito:mockito-core"113 )114 )115 }116 // Project Reactor117 object Reactor {118 // https://github.com/reactor/reactor-core119 val Core = DependencySpec("io.projectreactor:reactor-core", Versions.Reactor)120 }121 // Protobuf122 object Protobuf {123 val Java = DependencySpec("com.google.protobuf:protobuf-java", Versions.Protobuf)124 val JavaUtil = DependencySpec("com.google.protobuf:protobuf-java-util", Versions.Protobuf)125 }126 object Kong {127 val Unirest = DependencySpec("com.konghq:unirest-java", Versions.Unirest)128 }129 object Jackson {130 val Databind = DependencySpec(131 "com.fasterxml.jackson.core:jackson-databind",132 "2.12.6.1"133 )134 val Datatype = DependencySpec(135 "com.fasterxml.jackson.datatype:jackson-datatype-jsr310",136 "2.12.+"137 )138 val KotlinModule = DependencySpec(139 "com.fasterxml.jackson.module:jackson-module-kotlin",140 Versions.Jackson141 )142 val Hubspot = DependencySpec(143 "com.hubspot.jackson:jackson-datatype-protobuf",144 "0.9.9-jackson2.9-proto3"145 )146 }147 object Provenance {148 val KeyAccessLib = DependencySpec("io.provenance.originator-key-access-lib:lib", Versions.KeyAccessLib)149 val ProtoKotlin = DependencySpec("io.provenance:proto-kotlin", Versions.ProvenanceProto)150 val AssetModel = DependencySpec("io.provenance.model:metadata-asset-model", Versions.AssetModel)151 val LoanPackage = DependencySpec("io.provenance.loan-package:contract", Versions.LoanPackage)152 object Client {153 val GrpcClientKotlin = DependencySpec("io.provenance.client:pb-grpc-client-kotlin", Versions.ProvenanceClient)154 }155 object HdWallet {156 val HdWallet = DependencySpec("io.provenance.hdwallet:hdwallet", Versions.ProvenanceHdWallet)157 val HdWalletBip39 = DependencySpec("io.provenance.hdwallet:hdwallet-bip39", Versions.ProvenanceHdWallet)158 }159 }160 object Grpc {161 val Protobuf = DependencySpec("io.grpc:grpc-protobuf", Versions.Grpc)162 val Stub = DependencySpec("io.grpc:grpc-stub", Versions.Grpc)163 }164 val KotlinLogging = DependencySpec("io.github.microutils:kotlin-logging-jvm", Versions.KotlinLogging)165 val Ktlint = DependencySpec("com.pinterest:ktlint", Versions.Ktlint)166 val Mockk = DependencySpec("io.mockk:mockk", Versions.Mockk)167 val Kotest = DependencySpec("io.kotest:kotest-runner-junit5-jvm", Versions.Kotest)168 val KotestAssertions = DependencySpec("io.kotest:kotest-assertions-core-jvm", Versions.Kotest)169 val KotestAssertionsArrow = DependencySpec("io.kotest.extensions:kotest-assertions-arrow", Versions.KotestExtensionsArrow)170 val KotestSpring = DependencySpec("io.kotest.extensions:kotest-extensions-spring", Versions.KotestSpring)171 val KotestProperty = DependencySpec("io.kotest:kotest-property", Versions.Kotest)172 val Hamkrest = DependencySpec("com.natpryce:hamkrest", Versions.Hamkrest)173 val Redisson = DependencySpec("org.redisson:redisson", Versions.Redisson)174 val SpringMockk = DependencySpec("com.ninja-squad:springmockk", Versions.SpringMockk)175 val KotlinFaker = DependencySpec("io.github.serpro69:kotlin-faker", Versions.KotlinFaker)176 object Swagger {177 val Annotations = DependencySpec("io.swagger:swagger-annotations", Versions.Swagger)178 }179 val Reflections = DependencySpec("org.reflections:reflections", Versions.Reflections)180 val BouncyCastleProvider = DependencySpec("org.bouncycastle:bcprov-jdk15on", Versions.BouncyCastle)181 val BouncyCastle = DependencySpec("org.bouncycastle:bcpkix-jdk15on", Versions.BouncyCastle)182 object TestContainers {183 val Core = DependencySpec("io.kotest.extensions:kotest-extensions-testcontainers", Versions.TestContainer)184 }185}186data class PluginSpec(187 val id: String,188 val version: String = ""189) {190 fun addTo(scope: PluginDependenciesSpec) {191 scope.also {192 it.id(id).version(version.takeIf { v -> v.isNotEmpty() })193 }194 }195 fun addTo(action: ObjectConfigurationAction) {196 action.plugin(this.id)197 }198}199data class DependencySpec(200 val name: String,201 val version: String = "",202 val isChanging: Boolean = false,203 val exclude: List<String> = emptyList()204) {205 fun plugin(scope: PluginDependenciesSpec) {206 scope.apply {207 id(name).version(version.takeIf { it.isNotEmpty() })208 }209 }210 fun classpath(scope: ScriptHandlerScope) {211 val spec = this212 with(scope) {213 dependencies {214 classpath(spec.toDependencyNotation())215 }216 }217 }218 fun implementation(handler: DependencyHandlerScope) {219 val spec = this...

Full Screen

Full Screen

SharedJdbcDatabaseContainerExtension.kt

Source:SharedJdbcDatabaseContainerExtension.kt Github

copy

Full Screen

2import com.zaxxer.hikari.HikariConfig3import com.zaxxer.hikari.HikariDataSource4import io.kotest.core.extensions.MountableExtension5import io.kotest.core.listeners.AfterProjectListener6import io.kotest.core.listeners.AfterSpecListener7import io.kotest.core.listeners.AfterTestListener8import io.kotest.core.listeners.BeforeSpecListener9import io.kotest.core.listeners.BeforeTestListener10import io.kotest.core.spec.Spec11import io.kotest.core.test.TestCase12import io.kotest.core.test.TestResult13import org.testcontainers.containers.JdbcDatabaseContainer14import java.sql.Connection15/**16 * A Kotest [MountableExtension] for [JdbcDatabaseContainer]s that are started the first time they are17 * installed in a test, and then shared throughout the same gradle module. The container is shutdown18 * after all specs have completed.19 *20 * If no spec is executed that installs a particular container, then that container is never started.21 *22 * This extension will create a pooled [HikariDataSource] attached to the database and23 * return that to the user as the materialized value.24 *25 * The Hikari pool can be configured in the constructor through the [configure] parameter, or through26 * the install method per spec. If the latter option is used, then only the configure function from27 * the install where the container is first started will be executed.28 *29 * Note: This extension requires Kotest 5.0+30 *31 * @param container the specific database test container type32 * @param beforeSpec a beforeSpec callback33 * @param afterSpec an afterSpec callback34 * @param beforeTest a beforeTest callback35 * @param afterTest a afterTest callback36 * @param afterStart called one time, after the container is started37 * @param configure a callback to configure the [HikariConfig] instance that is used to create the [HikariDataSource].38 *39 * @since 1.3.040 */41class SharedJdbcDatabaseContainerExtension(42 private val container: JdbcDatabaseContainer<*>,43 private val beforeTest: suspend (HikariDataSource) -> Unit = {},44 private val afterTest: suspend (HikariDataSource) -> Unit = {},45 private val beforeSpec: suspend (HikariDataSource) -> Unit = {},46 private val afterSpec: suspend (HikariDataSource) -> Unit = {},47 private val afterStart: (HikariDataSource) -> Unit = {},48 private val configure: TestContainerHikariConfig.() -> Unit = {},49) : MountableExtension<TestContainerHikariConfig, HikariDataSource>,50 AfterProjectListener,51 BeforeTestListener,52 BeforeSpecListener,53 AfterTestListener,54 AfterSpecListener {55 private var ds: HikariDataSource? = null56 override fun mount(configure: TestContainerHikariConfig.() -> Unit): HikariDataSource {57 if (!container.isRunning) {58 container.start()59 ds = createDataSource().apply(afterStart)60 }61 return ds ?: error("DataSource was not initialized")62 }63 override suspend fun afterProject() {64 if (container.isRunning) container.stop()65 }66 override suspend fun beforeTest(testCase: TestCase) {67 beforeTest(ds ?: error("DataSource was not initialized"))68 }69 override suspend fun afterTest(testCase: TestCase, result: TestResult) {70 afterTest(ds ?: error("DataSource was not initialized"))71 }72 override suspend fun beforeSpec(spec: Spec) {73 beforeSpec(ds ?: error("DataSource was not initialized"))74 }75 override suspend fun afterSpec(spec: Spec) {76 afterSpec(ds ?: error("DataSource was not initialized"))77 }78 private fun runInitScripts(connection: Connection, dbInitScripts: List<String>) {79 if (dbInitScripts.isNotEmpty()) {80 val scriptRunner = ScriptRunner(connection)81 dbInitScripts.forEach { script ->82 ResourceLoader()83 .resolveResource(script)84 .filter { it.endsWith(".sql") }85 .forEach { scriptRunner.runScript(it.loadToReader()) }86 }87 }88 }89 private fun createDataSource(): HikariDataSource {90 val config = TestContainerHikariConfig()...

Full Screen

Full Screen

SharedTestContainerExtension.kt

Source:SharedTestContainerExtension.kt Github

copy

Full Screen

1package io.kotest.extensions.testcontainers2import io.kotest.core.extensions.MountableExtension3import io.kotest.core.listeners.AfterProjectListener4import io.kotest.core.listeners.AfterSpecListener5import io.kotest.core.listeners.AfterTestListener6import io.kotest.core.listeners.BeforeSpecListener7import io.kotest.core.listeners.BeforeTestListener8import io.kotest.core.spec.Spec9import io.kotest.core.test.TestCase10import io.kotest.core.test.TestResult11import org.testcontainers.containers.GenericContainer12/**13 * A Kotest [MountableExtension] for [GenericContainer]s that are started the first time they are14 * installed in a test, and then shared throughout the same gradle module. The container is shutdown15 * after all specs have completed.16 *17 * If no spec is executed that installs a particular container, then that container is never started.18 *19 * The returned materialized value can be adapted through the [mapper] parameter, to allow returning something other20 * than the raw container. For example, you could return a RedisClient that was preconnected to a redis container,21 * rather than returning the container itself.22 *23 * Note: This extension requires Kotest 5.0+24 *25 * @param container the specific database test container type26 * @param beforeSpec a beforeSpec callback, can be used to configure the container.27 * @param afterSpec an afterSpec callback, can be used to configure the container.28 * @param beforeTest a beforeTest callback, can be used to configure the container.29 * @param afterTest a afterTest callback, can be used to configure the container.30 * @param configure called one time after the container is started. Can configure the container without needing to31 * specify the configuration code at every use site.32 * @param mapper optional mapping function to adapt the materialized value.33 *34 * @since 1.3.035 */36class SharedTestContainerExtension<T : GenericContainer<*>, U>(37 private val container: T,38 private val beforeTest: suspend (T) -> Unit = {},39 private val afterTest: suspend (T) -> Unit = {},40 private val beforeSpec: suspend (T) -> Unit = {},41 private val afterSpec: suspend (T) -> Unit = {},42 private val configure: T.() -> Unit = {},43 private val mapper: T.() -> U,44) : MountableExtension<T, U>,45 AfterProjectListener,46 BeforeTestListener,47 BeforeSpecListener,48 AfterTestListener,49 AfterSpecListener {50 companion object {51 operator fun <T : GenericContainer<*>> invoke(52 container: T,53 beforeTest: (T) -> Unit = {},54 afterTest: (T) -> Unit = {},55 beforeSpec: (T) -> Unit = {},56 afterSpec: (T) -> Unit = {},57 configure: T.() -> Unit = {},58 ): SharedTestContainerExtension<T, T> {59 return SharedTestContainerExtension(60 container,61 beforeTest,62 afterTest,63 beforeSpec,64 afterSpec,65 configure66 ) { this }67 }68 }69 override fun mount(configure: T.() -> Unit): U {70 if (!container.isRunning) {71 container.start()72 configure(container)73 this@SharedTestContainerExtension.configure(container)74 }75 return this@SharedTestContainerExtension.mapper(container)76 }77 override suspend fun afterProject() {78 if (container.isRunning) container.stop()79 }80 override suspend fun beforeTest(testCase: TestCase) {81 beforeTest(container)82 }83 override suspend fun afterTest(testCase: TestCase, result: TestResult) {84 afterTest(container)85 }86 override suspend fun beforeSpec(spec: Spec) {87 beforeSpec(container)88 }89 override suspend fun afterSpec(spec: Spec) {90 afterSpec(container)91 }92}...

Full Screen

Full Screen

KotestStringSpecTest.kt

Source:KotestStringSpecTest.kt Github

copy

Full Screen

2import com.example.logger3import io.kotest.assertions.fail4import io.kotest.core.extensions.Extension5import io.kotest.core.listeners.TestListener6import io.kotest.core.spec.Spec7import io.kotest.core.spec.style.StringSpec8import io.kotest.core.test.TestCase9import io.kotest.core.test.TestResult10import kotlin.reflect.KClass11class KotestStringSpecTest : StringSpec({12 val logger = logger<KotestStringSpecTest>()13 val list = mutableListOf<String>()14 fun add(item: String) {15 list.add(item)16 }17 add("init-1")18 logger.info("init 1, list: {}", list)19 "foo" {20 add("foo")21 logger.info("foo, list: {}", list)22 }23 add("init-2")24 logger.info("init 2, list: {}", list)25 "fail" {26 add("fail")27 logger.info("fail, list: {}", list)28 fail("fail, list: $list")29 }30 "bar" {31 add("bar")32 logger.info("bar, list: {}", list)33 }34})35class KotestStringSpecTest2: StringSpec() {36 private val logger = logger<KotestStringSpecTest2>()37 init {38 val list = mutableListOf<String>()39 fun add(item: String) {40 list.add(item)41 }42 add("init-1")43 logger.info("init 1, list: {}", list)44 "foo" {45 add("foo")46 logger.info("foo, list: {}", list)47 }48 add("init-2")49 logger.info("init 2, list: {}", list)50 "fail" {51 add("fail")52 logger.info("fail, list: {}", list)53 fail("fail, list: $list")54 }55 "bar" {56 add("bar")57 logger.info("bar, list: {}", list)58 }59 }60 override fun afterSpec(spec: Spec) {61 logger.info("afterSpec")62 }63 override fun afterTest(testCase: TestCase, result: TestResult) {64 logger.info("afterTest")65 }66 override fun beforeSpec(spec: Spec) {67 logger.info("beforeSpec")68 }69 override fun beforeTest(testCase: TestCase) {70 logger.info("beforeTest")71 }72 override fun extensions(): List<Extension> {73 logger.info("extensions")74 return listOf(object : Extension {})75 }76 override fun listeners(): List<TestListener> {77 logger.info("listeners")78 return listOf(ExampleListener)79 }80}81object ExampleListener: TestListener {82 private val logger = logger<ExampleListener>()83 override suspend fun afterInvocation(testCase: TestCase, iteration: Int) {84 logger.info("afterInvocation ${testCase.displayName}")85 }86 override suspend fun afterSpec(spec: Spec) {87 val names = spec.rootTests().map { it.testCase.displayName }88 logger.info("afterSpec $names")89 }90 override suspend fun afterTest(testCase: TestCase, result: TestResult) {91 logger.info("afterTest ${testCase.displayName}, ${result.status} ${result.reason} ${result.error}")92 }93 override suspend fun beforeInvocation(testCase: TestCase, iteration: Int) {94 logger.info("beforeInvocation ${testCase.displayName}")95 }96 override suspend fun beforeSpec(spec: Spec) {97 val names = spec.rootTests().map { it.testCase.displayName }98 logger.info("beforeSpec $names")99 }100 override suspend fun beforeTest(testCase: TestCase) {101 logger.info("beforeTest ${testCase.displayName}")102 }103 override suspend fun finalizeSpec(kclass: KClass<out Spec>, results: Map<TestCase, TestResult>) {104 logger.info("finalizeSpec")105 }106 override suspend fun prepareSpec(kclass: KClass<out Spec>) {107 logger.info("prepareSpec")108 }109}...

Full Screen

Full Screen

Kotest.kt

Source:Kotest.kt Github

copy

Full Screen

1package io.kotest.plugin.pitest2import io.kotest.core.spec.style.FunSpec3import io.kotest.core.spec.style.StringSpec4import io.kotest.core.spec.style.WordSpec5import io.kotest.matchers.collections.shouldBeEmpty6import io.kotest.matchers.collections.shouldHaveSize7import io.kotest.matchers.shouldBe8class Kotest : FunSpec() {9 init {10 test("StringSpecs") {11 val resultCollector = findTestsIn(StringSpecs::class.java)12 resultCollector.skipped.shouldBeEmpty()13 resultCollector.started.shouldHaveSize(2)14 resultCollector.ended.shouldHaveSize(2)15 resultCollector.failures.shouldHaveSize(1)16 }17 test("FunSpecs") {18 val resultCollector = findTestsIn(FunSpecs::class.java)19 resultCollector.skipped.shouldBeEmpty()20 resultCollector.started.shouldHaveSize(2)21 resultCollector.ended.shouldHaveSize(2)22 resultCollector.failures.shouldHaveSize(1)23 }24 test("WordSpecs") {25 val resultCollector = findTestsIn(WordSpecs::class.java)26 resultCollector.skipped.shouldBeEmpty()27 resultCollector.started.shouldHaveSize(7)28 resultCollector.ended.shouldHaveSize(7)29 resultCollector.failures.shouldHaveSize(2)30 }31 }32 private fun findTestsIn(clazz: Class<*>): TestResultCollector {33 val resultCollector = TestResultCollector()34 KotestUnitFinder().findTestUnits(clazz)35 .stream()36 .forEach { testUnit -> testUnit.execute(resultCollector) }37 return resultCollector38 }39}40private class FunSpecs : FunSpec() {41 init {42 test("passing test") { 1 shouldBe 1 }43 test("failing test") { 1 shouldBe 2 }44 }45}46private class StringSpecs : StringSpec() {47 init {48 "passing test" { 1 shouldBe 1 }49 "failing test" { 1 shouldBe 2 }50 }51}52private class WordSpecs : WordSpec() {53 init {54 "should container" should {55 "passing test" { 1 shouldBe 1 }56 "failing test" { 1 shouldBe 2 }57 }58 "when container" `when` {59 "nested should container" should {60 "passing test" { 1 shouldBe 1 }61 "failing test" { 1 shouldBe 2 }62 }63 }64 }65}...

Full Screen

Full Screen

ExampleSpec.kt

Source:ExampleSpec.kt Github

copy

Full Screen

2import arrow.core.Either3import arrow.optics.Traversal4import arrow.typeclasses.Monoid5import io.kotest.assertions.arrow.core.shouldBeRight6import io.kotest.core.spec.style.StringSpec7import io.kotest.matchers.shouldBe8import io.kotest.matchers.types.shouldBeTypeOf9import io.kotest.property.Arb10import io.kotest.property.arbitrary.int11import io.kotest.property.arbitrary.list12import io.kotest.property.arbitrary.map13import io.kotest.property.arbitrary.positiveInt14import io.kotest.property.arbitrary.string15import io.kotest.property.arrow.core.MonoidLaws16import io.kotest.property.arrow.core.either17import io.kotest.property.arrow.core.functionAToB18import io.kotest.property.arrow.laws.testLaws19import io.kotest.property.arrow.optics.TraversalLaws20import kotlin.jvm.JvmInline21class ExampleSpec : StringSpec({22 "true shouldBe true" {23 true shouldBe true24 }25 "exception should fail" {26 // throw RuntimeException("Boom2!")27 }28 "kotest arrow extension use-cases" {29 // smart-cast abilities for arrow types30 Either.Right("HI").shouldBeRight().shouldBeTypeOf<String>()31 }32 // utilise builtin or costume Laws with Generators to verify behavior33 testLaws(34 MonoidLaws.laws(Monoid.list(), Arb.list(Arb.string())),35 MonoidLaws.laws(Monoid.numbers(), Arb.numbers())...

Full Screen

Full Screen

NumberTestByStringSpec.kt

Source:NumberTestByStringSpec.kt Github

copy

Full Screen

1import io.kotest.core.spec.style.StringSpec2import io.kotest.data.forAll3import io.kotest.data.headers4import io.kotest.data.row5import io.kotest.data.table6import io.kotest.matchers.shouldBe7class NumberTestByStringSpec : StringSpec() {8 init {9 "isOdd:: when value is odd number then return true" {10 val number = Number(1)11 number.isOdd() shouldBe true12 }13 "isOdd:: when value is even number then return false" {14 val number = Number(2)15 number.isOdd() shouldBe false16 }17 "isRange:: when value in range then return true" {18 forAll(19 table(20 headers("value"),21 row(1),...

Full Screen

Full Screen

KotestEnvsTest.kt

Source:KotestEnvsTest.kt Github

copy

Full Screen

1package kotest.envs2import io.micronaut.runtime.EmbeddedApplication3import io.micronaut.test.extensions.kotest.annotation.MicronautTest4import io.kotest.core.spec.style.StringSpec5import io.kotest.matchers.shouldBe6@MicronautTest7class KotestEnvsTest(private val application: EmbeddedApplication<*>): StringSpec({8 "test the server is running" {9 assert(application.isRunning)10 }11 "test config is read from application-test.yml" {12 application.applicationContext.getProperty("config.value", String::class.java).get() shouldBe "fromtestyml"13 }14})...

Full Screen

Full Screen

Spec

Using AI Code Generation

copy

Full Screen

1class StringSpecExampleTest : StringSpec({2 "test" {3 }4})5class FunSpecExampleTest : FunSpec({6 test("test") {7 }8})9class BehaviorSpecExampleTest : BehaviorSpec({10 Given("test") {11 When("test") {12 Then("test") {13 }14 }15 }16})17class ExpectSpecExampleTest : ExpectSpec({18 context("test") {19 expect("test") {20 }21 }22})23class WordSpecExampleTest : WordSpec({24 "test" should {25 "test" {26 }27 }28})29class FeatureSpecExampleTest : FeatureSpec({30 feature("test") {31 scenario("test") {32 }33 }34})35class DescribeSpecExampleTest : DescribeSpec({36 describe("test") {37 it("test") {38 }39 }40})41class FreeSpecExampleTest : FreeSpec({42 "test" - {43 "test" {44 }45 }46})47class AnnotationSpecExampleTest : AnnotationSpec() {48 fun test() {49 }50}51class ShouldSpecExampleTest : ShouldSpec({52 "test" {53 should("test") {54 }55 }56})57class StringSpecExampleTest : StringSpec({58 "test" {59 }60})

Full Screen

Full Screen

Spec

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.StringSpec2class MyTest : StringSpec({3 "test" {4 }5})6import io.kotest.core.spec.style.FunSpec7class MyTest : FunSpec({8 test("test") {9 }10})11import io.kotest.core.spec.style.DescribeSpec12class MyTest : DescribeSpec({13 describe("test") {14 }15})16import io.kotest.core.spec.style.FeatureSpec17class MyTest : FeatureSpec({18 feature("test") {19 }20})21import io.kotest.core.spec.style.FreeSpec22class MyTest : FreeSpec({23 "test" - {24 }25})26import io.kotest.core.spec.style.ExpectSpec27class MyTest : ExpectSpec({28 context("test") {29 }30})31import io.kotest.core.spec.style.ShouldSpec32class MyTest : ShouldSpec({33 "test" {34 }35})36import io.kotest.core.spec.style.BehaviorSpec37class MyTest : BehaviorSpec({38 Given("test") {39 }40})41import io.kotest.core.spec.style.WordSpec42class MyTest : WordSpec({43 "test" should {44 }45})46import io.kotest.core.spec.style.AnnotationSpec47class MyTest : AnnotationSpec() {48 fun test() {49 }50}51import io.kotest.core.spec.style.FreeSpec52class MyTest : FreeSpec() {53 init {

Full Screen

Full Screen

Spec

Using AI Code Generation

copy

Full Screen

1class MySpec : FunSpec() {2init {3test("test 1") {4}5}6}7class MySpec : BehaviorSpec() {8init {9Given("Given 1") {10When("When 1") {11Then("Then 1") {12}13}14}15}16class MySpec : FeatureSpec() {17init {18feature("feature 1") {19scenario("scenario 1") {20}21}22}23}24class MySpec : FreeSpec() {25init {26"Given 1" - {27"When 1" - {28"Then 1" {29}30}31}32}33}34class MySpec : ShouldSpec() {35init {36should("test 1") {37}38}39}40class MySpec : StringSpec() {41init {42"test 1" {43}44}45}46class MySpec : WordSpec() {47init {48"Given 1" When {49"When 1" Then {50"Then 1" {51}52}53}54}55}56class MySpec : DescribeSpec() {57init {58describe("Given 1") {59context("When 1") {60it("Then 1") {61}62}63}64}65class MySpec : ExpectSpec() {66init {67context("Given 1") {68expect("When 1") {69}70}71}72}73class MySpec : FunSpec() {74init {75test("test 1") {76}77}78}79class MySpec : BehaviorSpec() {80init {81Given("Given 1") {82When("When 1") {83Then("Then 1") {

Full Screen

Full Screen

Spec

Using AI Code Generation

copy

Full Screen

1class MySpec : FunSpec({2 test("hello") {3 }4})5class MySpec : FunSpec({6 describe("hello") {7 }8})9class MySpec : FunSpec({10 context("hello") {11 }12})13class MySpec : FunSpec({14 it("hello") {15 }16})17class MySpec : FunSpec({18 should("hello") {19 }20})21class MySpec : FunSpec({22 on("hello") {

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful