https://kotlinlang.org logo
#getting-started
Title
# getting-started
r

Ray Rahke

03/12/2024, 7:51 PM
How can I tell JUnit to expect my
test/
folder in a different location than under
src/
?
not kotlin but kotlin colored 2
j

Javier

03/12/2024, 8:18 PM
You don’t need to tell junit anything. Just add any directory to the test source set and it will work
r

Ray Rahke

03/12/2024, 8:18 PM
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

Javier

03/12/2024, 8:19 PM
yes, in the kotlin extension you can access to each source set
r

Ray Rahke

03/12/2024, 8:20 PM
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

Javier

03/12/2024, 8:22 PM
You don’t need to do anything with junit to get what you want working
Copy code
kotlin.sourceSets.test.srcDirs(“…”)
r

Ray Rahke

03/12/2024, 8:23 PM
Copy code
repositories {
    mavenCentral()
}
plugins {
    kotlin("jvm") version "1.9.23"
}
dependencies {
    testImplementation(kotlin("test"))
}
kotlin.sourceSets.test.srcDirs("…")
so this?
j

Javier

03/12/2024, 8:23 PM
add your directories in
srcDirs
r

Ray Rahke

03/12/2024, 8:24 PM
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

Javier

03/12/2024, 8:25 PM
if that does not work that means it is relative to the project and you would need something like
rootDir.resolve(“test”).path
r

Ray Rahke

03/13/2024, 1:55 AM
@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

Javier

03/13/2024, 3:01 AM
Copy code
kotlin.sourceSets.test.kotlin.srcDirs(“…”)