Skip to content

Instantly share code, notes, and snippets.

@wpanas
Last active March 19, 2022 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpanas/5dc8cf2079859f1e0afa972c7ffa71a2 to your computer and use it in GitHub Desktop.
Save wpanas/5dc8cf2079859f1e0afa972c7ffa71a2 to your computer and use it in GitHub Desktop.
Kotest Example
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")
}
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