https://kotlinlang.org logo
#intellij
Title
# intellij
j

Javier

01/10/2023, 12:21 PM
Is it possible to indicate to IntelliJ, via Gradle, that a source directory is for tests? For example,
test/kotlin
is green, meanwhile
functionalTest/kotlin
is blue.
s

Starr

01/10/2023, 12:26 PM
how are you adding the
functionalTest
source set? idk if IJ detects whether it depends on
test
or whatever you can use
Mark As > Test Sources
in the UI but that wouldn't persist
r

Riccardo Lippolis

01/10/2023, 12:28 PM
I use the following Gradle config to mark an
integrationTest
directory (from the sourceset
integrationTestSourceSet
) as test sources, by using the
idea
plugin:
Copy code
plugins {
    // ... other plugins

    idea
}

idea {
    module {
        testSources.from(integrationTestSourceSet.allSource.sourceDirectories)
    }
}
j

Javier

01/10/2023, 12:36 PM
I am adding it so
Copy code
sourceSets.register("functionalTest")
@Riccardo Lippolis without that plugin is not possible right? I am not using it yet as it is not compatible with project isolation
r

Riccardo Lippolis

01/10/2023, 12:38 PM
I don't think so. It's an IntelliJ-specific setting, so it has to be configured in the IntelliJ configuration. If you want to do that from the Gradle build file, the
idea
plugin is suitable for that. So if you want to keep the Gradle file independent from IntelliJ-specific stuff, that's not an option 😅
e

Emil Kantis

01/10/2023, 12:46 PM
if you use the jvm-test-suite plugin you can create another test suite and it should be picked up correctly IIRC..
j

Javier

01/10/2023, 12:47 PM
that plugin is not compatible with KMP, right?
e

Emil Kantis

01/10/2023, 12:48 PM
I suppose not, considering it's naming, but can't say for sure 😁
j

Javier

01/10/2023, 12:48 PM
@Riccardo Lippolis as they are doing that automatically for
test
, I would expect something similar for other regex like
fooTest
or
testFoo
r

Riccardo Lippolis

01/10/2023, 12:52 PM
maybe this works for you: https://www.jetbrains.com/help/idea/testing.html#gradle-use-custom-test-root it looks like it's an array, so maybe you can supply multiple source directories there (I haven't tried it)
j

Javier

01/10/2023, 1:05 PM
yeah I could use this one, but I would have to do that on each project, I would keep it as blue until idea plugin is fixed
r

Riccardo Lippolis

01/10/2023, 1:07 PM
but if you define it in the Gradle build file, you would still have to do that on each project, right? I mean, regardless of whether you're using the
idea
plugin
j

Javier

01/10/2023, 1:08 PM
I don't follow you 🤔, they are already picked by intellij via gradle, the only problem is they are not colored with green in the editor, but I can run them with right click run tests for example
so intellij knows it is a source set and it contains tests and it is able to run them, but it is not marked with the green color, but you can run all test in
main
too
r

Riccardo Lippolis

01/10/2023, 1:42 PM
so, your original question was that you want to make the
functionalTest/kotlin
directory shown as a test sources dir in IntelliJ (make it green). So I suggested the
idea
plugin. So then you asked if it was possible without the plugin, so I sent you the link to the IDEA documentation describing a way that would not involve the plugin, something like this:
Copy code
sourceSets {
    test {
        kotlin {
            srcDirs("src/test/kotlin", "src/functionalTest/kotlin")
        }
    }
}
you then said "yeah I could use this one, but I would have to do that on each project", which is the point where I lost you (and you lost me as well, probably) 😛
24 Views