https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
b

Big Chungus

02/10/2023, 4:34 PM
Has anyone figured out how to add a custom jvm sourceSet and testSuite in an mpp project? Something like
jvmIntegrationTest
b

Big Chungus

02/10/2023, 4:51 PM
Thanks, that helped
Copy code
jvm {
    compilations {
      val main by getting
      val instrumentedTest by creating {
        defaultSourceSet.dependsOn(main.defaultSourceSet)
      }
      val testTask = tasks.register<Test>("jvmInstrumentedTest") {
        group = "verification"
        classpath = instrumentedTest.runtimeDependencyFiles
      }
      tasks.named("allTests") { dependsOn(testTask) }
    }
  }
Wait, not quite - my tests are still not getting picked up
Copy code
compilations {
      val main by getting
      val instrumentedTest by creating {
        defaultSourceSet.dependsOn(main.defaultSourceSet)
      }
      val testTask = tasks.register<Test>("jvmInstrumentedTest") {
        dependsOn(instrumentedTest.compileTaskProvider)
        group = "verification"
        classpath = instrumentedTest.runtimeDependencyFiles
        testClassesDirs = instrumentedTest.defaultSourceSet.kotlin.sourceDirectories
      }
      tasks.named("allTests") { dependsOn(testTask) }
    }
With this I'm getting test class picked up, but the test run is failing with
ClassNotFoundException
for the test class
Copy code
compilations {
      val main by getting
      val instrumentedTest by creating {
        defaultSourceSet.dependsOn(main.defaultSourceSet)
      }
      val testTask = tasks.register<Test>("jvmInstrumentedTest") {
        dependsOn(instrumentedTest.compileTaskProvider)
        group = "verification"
        classpath =
          instrumentedTest.compileDependencyFiles + instrumentedTest.runtimeDependencyFiles
        testClassesDirs = instrumentedTest.output.classesDirs
        shouldRunAfter("jvmTest")
        testLogging { events("passed") }
      }
      tasks.named("allTests") { dependsOn(testTask) }
    }
6 Views