How can I tell JUnit to expect my `test/` folder i...
# getting-started
r
How can I tell JUnit to expect my
test/
folder in a different location than under
src/
?
not kotlin but kotlin colored 2
j
You don’t need to tell junit anything. Just add any directory to the test source set and it will work
r
is that in the build.gradle.kts?
this is all of my contents ``````
Copy code
repositories {
    mavenCentral()
}
plugins {
    kotlin("jvm") version "1.9.23"
}
dependencies {
    testImplementation(kotlin("test"))
}
j
yes, in the kotlin extension you can access to each source set
r
i am having a hard time knowing how to figure out what to write here
like, what the names of each things are.
the kotlin docs don't mention it on junit
Copy code
repositories {
    mavenCentral()
}
plugins {
    kotlin("jvm") version "1.9.23"
}
dependencies {
    testImplementation(kotlin("test"))
}
kotlin {
  sourceSets {

} }
j
You don’t need to do anything with junit to get what you want working
Copy code
kotlin.sourceSets.test.srcDirs(“…”)
r
Copy code
repositories {
    mavenCentral()
}
plugins {
    kotlin("jvm") version "1.9.23"
}
dependencies {
    testImplementation(kotlin("test"))
}
kotlin.sourceSets.test.srcDirs("…")
so this?
j
add your directories in
srcDirs
r
yeah
Copy code
repositories {
    mavenCentral()
}
plugins {
    kotlin("jvm") version "1.9.23"
}
dependencies {
    testImplementation(kotlin("test"))
}
kotlin.sourceSets.test.srcDirs("/test")
for my root level
folder named test
j
if that does not work that means it is relative to the project and you would need something like
rootDir.resolve(“test”).path
r
@Javier this
Copy code
repositories {
    mavenCentral()
}
plugins {
    kotlin("jvm") version "1.9.23"
}
dependencies {
    testImplementation(kotlin("test"))
}
kotlin.sourceSets.test.srcDirs("/test")
results in error
Copy code
* What went wrong:
Script compilation error:

  Line 10: kotlin.sourceSets.test.srcDirs("/test")
                                  ^ Unresolved reference: srcDirs
changing it to this
Copy code
repositories {
    mavenCentral()
}
plugins {
    kotlin("jvm") version "1.9.23"
}
dependencies {
    testImplementation(kotlin("test"))
}
rootDir.resolve("test").path
results in this error
Copy code
* What went wrong:
Script compilation errors:

  Line 10: rootDir.resolve("test").path
                           ^ Expecting an expression

  Line 10: rootDir.resolve("test").path
                           ^ Expecting ')'

  Line 10: rootDir.resolve("test").path
                                ^ Expecting an element

  Line 10: rootDir.resolve("test").path
                                 ^ Expecting an element

  Line 10: rootDir.resolve("test").path
                                  ^ Expecting an element

  Line 10: rootDir.resolve("test").path
                   ^ Overload resolution ambiguity: 
                       public fun File.resolve(relative: File): File defined in <http://kotlin.io|kotlin.io>
                       public fun File.resolve(relative: String): File defined in <http://kotlin.io|kotlin.io>
j
Copy code
kotlin.sourceSets.test.kotlin.srcDirs(“…”)