Skip to content

Instantly share code, notes, and snippets.

@picuu
Last active January 22, 2024 21:28
Show Gist options
  • Save picuu/f3a5adc61da7335351e90e7ee455c38f to your computer and use it in GitHub Desktop.
Save picuu/f3a5adc61da7335351e90e7ee455c38f to your computer and use it in GitHub Desktop.
IntelliJ Config for Dokka and JUnit

IntelliJ Config for Dokka and JUnit

Dokka for KDoc documentation

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.

image

In order to generate the documentation, open the terminal and run this command ./gradlew dokkaHtml.

JUnit5 fot Unit Testing

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.

image

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 }

Solutions to possible errors

Important

In case that the src/test/kotlin folder doesnt appear in your project, you can create it very easly.

image image

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.

image

@AlanTeixido
Copy link

impressive!

@ulisescastell
Copy link

let's fail tomorrow's exam

@ulisescastell
Copy link

tysm as well :)

@oscarsxrrano
Copy link

u are the best!!

@MartiVilas
Copy link

OMG! Thanks for that info! <3

@JesusCaballeroPr
Copy link

Eres un crack!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment