Tests population w/ dokkaHtml I am having trouble...
# dokka
j
Tests population w/ dokkaHtml I am having trouble getting Tests to populate in the dokkaHtml along with the classes and methods of the Main directory. Things I have tried in the build.gradle include: • Defining a new source set for the test files:
Copy code
tasks.dokkaHtml {
    dokkaSourceSets.configureEach {
        // Ensure this applies to the existing Dokka source sets
        when (name) {
            "main" -> {
                sourceRoots.from(file("src/main/kotlin"))
            }
            "test" -> {
                sourceRoots.from(file("src/test/kotlin"))
                displayName.set("Test Documentation")
                includes.from(file("src/test/kotlin"))
            }
        }
    }
}
• Specifying the package:
Copy code
tasks.dokkaHtml {
    dokkaSourceSets {
        named("main") {
            sourceRoots.from(file("src/main/kotlin"))
            displayName.set("Main Documentation")
        }
        named("test") {
            sourceRoots.from(file("src/test/kotlin"))
            displayName.set("Test Documentation")
            platform.set(org.jetbrains.dokka.Platform.jvm) // Specify JVM platform

            // Optional: Ensure packages are included
            perPackageOption {
                matchingRegex.set("com.timeCalculator.*")
                suppress.set(false)
            }
        }
    }
}
I have also tried to solve by treating the tests as separate modules and trying the Multi-Module approach as per the docs - to no avail. I have also had a good search through the thread here but didn't come across anything super apparent as a solution. I apologise for any naivety as I am fairly new to Kotlin and programming in general. I would be appreciative of any advice. Cheers
o
Hey!
I am having trouble getting Tests to populate in the dokkaHtml along with the classes and methods of the Main directory.
First of all, I'm curious, why do you need to have tests available inside HTML API reference? As for the solution, probably you need to set
suppress
flag to
false
. Dokka populates
dokkaSourceSets
which are coming from KGP (Kotlin Gradle Plugin) and by default sets
suppress=true
for test source sets. So probably in your case you need to do just this:
Copy code
tasks.dokkaHtml {
    dokkaSourceSets {
        named("test") {
            suppress.set(false)
            displayName.set("Test Documentation")
        }
    }
}
platform
and
sourceRoots
will be configured automatically
j
Thank you so much, Oleg—your solution worked perfectly! 🙏 I’m a junior developer at a company specialising in writing tests for the auto industry. We’re aiming to showcase what our tests accomplish to clients in a clear and accessible way using KDoc and Dokka. Our goal is to provide a high-level overview without requiring clients to delve deeply into the codebase.
thank you color 1