I have a multi module project (its an intellij plugin) with shared script plugins, i want to configure the testing extension in a script plugin that’s shared by all projects like that:
testing {
suites {
val test by getting(JvmTestSuite::class) {
//this should be the only place to mention junit version, it applies to all projects.
useJUnitJupiter("5.8.2")
dependencies {
implementation(project)
}
}
}
}
i can also just configure the test task like that:
tasks.test {
useJUnitPlatform {
version = "5.8.2"
}
}
what is the difference between the two approaches?
is it redandant to configure the testing extension of jvm-test-suite if i’m not sure i will have multiple targets?
The difference between useJUnitPlatform and useJUnitJupiter is, that both are different things.
JUnit Platform is a generic platform on which test engines can run their supported tests.
Examples of such test engines are
JUnit Jupiter (the “JUnit 5 for writing the actual tests”)
JUnit Vintage (to run JUnit 4 tests on the JUnit Platform)
Spock (to run Spock framework based tests on the JUnit Platform [I exclusively use Spock since I know it, as it makes testing fun again )
…
So useJUnitPlatform just configures the JUnit Platform being the test platform of the task, but not which test engines to use. It only works with JUnit Jupiter if you add JUnit Jupiter as test dependency additionally.
useJUnitJupiter configures the JUnit Platform being the test platform of the test task and additionally adds the JUnit Jupiter dependency for you.
Btw. you should not need implementation(project), for the test suite this should be configured automatically by default.
is it redandant to configure the testing extension of jvm-test-suite if i’m not sure i will have multiple targets?
You cannot currently have multiple targets anyway. Currently, unfortunately, each test suite has exactly one target with one task, though I hope this gets extended in the near future.
Whether you configure the test task in the old way, or configure it using the new test suites DSL doesn’t matter much. But I personally currently prefer to do it through the new DSL.