Skip to content

Instantly share code, notes, and snippets.

@FouomaOscar
Created December 30, 2023 11:01
Show Gist options
  • Save FouomaOscar/37301c7caa4363000d6d089c1166f93e to your computer and use it in GitHub Desktop.
Save FouomaOscar/37301c7caa4363000d6d089c1166f93e to your computer and use it in GitHub Desktop.
kotlin test example with mockk
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.8.0"
application
}
group = "me.shantiswaruptunga"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("javax.xml.bind:jaxb-api:2.3.1")
testImplementation(kotlin("test"))
testImplementation("io.mockk:mockk:1.12.4")
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClass.set("MainKt")
}
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
import io.mockk.every
import io.mockk.mockk
import org.junit.jupiter.api.Test
import org.w3c.dom.Node
class XmlTest {
@Test
fun test2() {
val node1 = mockk<Node>()
every { node1.nodeName } returns "x"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment