Add id("org.jetbrains.dokka") version "1.9.10"
to the plugins section, in build.gradle.kts
.
If it doesn't work, try changing the version with your jvm version.
plugins {
kotlin("jvm") version "1.9.21"
id("org.jetbrains.dokka") version "1.9.10"
}
Next, add this to your build.gradle.kts
:
tasks.dokkaHtml.configure {
outputDirectory.set(project.layout.buildDirectory.dir("dokka"))
}
On last place, add dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.9.10")
to dependences section.
dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test")
dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.9.10")
}
You'll see this icons at the right top of the window. Click both and you should be fine.
In order to generate the documentation, open the terminal and run this command ./gradlew dokkaHtml
.
Add this testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
to the dependences section, in build.gradle.kts
.
dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
}
Then go to any function, right click and Generate.... Next, click Fix
and finally OK
.
This is the proper syntax of a test:
@Test
fun checkFunction() {
assertEquals(expected, functionToTest(params))
}
These are the most important asserts that exist:
- assertFalse(value)
- assertTrue(value)
- assertNotEquals(expected, valueToTest)
- assertEquals(expected, valueToTest)
- assertArrayEquals(expected, valueToTest)
- assertNull(value)
- assertNotNull(value)
- assertSame()
- assert(value) { message }
Important
In case that the src/test/kotlin
folder doesnt appear in your project, you can create it very easly.
Even if it still doesn't work, and your test files are being created in the same folder as your kotlin files, you can also try to reload the Gradle. Just open this little menu at the top right of your screen and then click the reload button.
impressive!