Last active
March 19, 2022 12:14
-
-
Save wpanas/5dc8cf2079859f1e0afa972c7ffa71a2 to your computer and use it in GitHub Desktop.
Kotest Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | |
plugins { | |
kotlin("jvm") version "1.6.10" | |
application | |
} | |
group = "com.github.wpanas" | |
version = "1.0-SNAPSHOT" | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
testImplementation("io.kotest:kotest-runner-junit5:5.2.1") | |
testImplementation("io.kotest:kotest-property:5.2.1") | |
} | |
tasks.withType<Test>().configureEach { | |
useJUnitPlatform() | |
} | |
tasks.withType<KotlinCompile> { | |
kotlinOptions.jvmTarget = "11" | |
} | |
application { | |
mainClass.set("MainKt") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.kotest.core.spec.style.WordSpec | |
import io.kotest.matchers.shouldBe | |
import io.kotest.property.Arb | |
import io.kotest.property.arbitrary.filter | |
import io.kotest.property.arbitrary.int | |
import io.kotest.property.checkAll | |
fun isEven(int: Int) = int % 2 == 0 | |
class IsEvenSpec : WordSpec({ | |
"isEven" should { | |
"return true for even integers" { | |
val evenIntegers = Arb.int().filter { it % 2 == 0 } | |
checkAll(evenIntegers) { evenInteger -> | |
isEven(evenInteger) shouldBe true | |
} | |
} | |
"return false for odd integers" { | |
val oddIntegers = Arb.int().filter { it % 2 == 1 } | |
checkAll(oddIntegers) { oddInteger -> | |
isEven(oddInteger) shouldBe false | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment