0

I would like to mark the classes of my systest sourceSet as unit test classes. I tried to mark them with the following code:

sourceSets {
  main {
    groovy {
      srcDirs = [
              'src/main/masks'
    }

    resources {
      srcDirs += 'src/main/journaltemplates'
    }
  }

  /* This brings up systest in the test resources */
  test.java.srcDir 'src/systest/java'
  test.resources.srcDir 'src/systest/resources'

  systest {
    java {
      srcDirs = ['src/systest/java']
    }

    resources {
      srcDirs = ['src/systest/resources']
    }
  }
}

With this solution the sourceset got marked as unit test class, but was additionally added to the test sourceSet which is not desired. I want to keep the classes in the systest sourceSet and specify that the systest sourceSet, is a unit test sourceSet. I want the same behaviour for the systest sourceSet as for the test sourceSet, but they should be distinct sourceSets.


The second solution i tried was using the idea plugin for gradle and modify the module setting, as seen in this SO post:

idea {
  module {
    testSourceDirs += file('src/systest')
  }
}

The problem with this solution is that the systest sources are added to the test sourceSet too.

Hopefully this is clear enough, otherwise please comment. Thank you.

Stefan Sprenger
  • 1,050
  • 20
  • 42

2 Answers2

1

There is a dedicated Gradle feature called Declarative Test Suite that supports this case:

testing {
    suites {
        val test by getting(JvmTestSuite::class) {
            useJUnitJupiter()
        }

        register("integrationTest", JvmTestSuite::class) {
            dependencies {
                implementation(project())
            }

            targets {
                all {
                    testTask.configure {
                        shouldRunAfter(test)
                    }
                }
            }
        }
    }
}

More: https://docs.gradle.org/current/userguide/java_testing.html#sec:configuring_java_integration_tests

Igor
  • 2,039
  • 23
  • 27
0

Please try this configuration:

apply plugin: "idea"
sourceSets {
    systest {

        java {
            compileClasspath = test.output + main.output
            runtimeClasspath = output + compileClasspath 
        }
    }

}

idea {
    module {
        testSourceDirs = sourceSets.systest.allSource.srcDirs
    }
}
y.bedrov
  • 5,318
  • 3
  • 22
  • 19