Hello! Does anyone know how to handle this depreca...
# community-support
s
Hello! Does anyone know how to handle this deprecation warning? I reviewed the documentation and nothing really stood out regarding
classpath
in the snippet of our
build.gradle
(below).
Relying on the convention for Test.testClassesDirs in custom Test tasks has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: <https://docs.gradle.org/8.7/userguide/upgrading_version_8.html#test_task_default_classpath>
Here is the relevant piece of the `build.gradle`:
Copy code
task navigationTest(type: Test, dependsOn: cleanTest) {
	useJUnit()
	ignoreFailures false
	include '**/somepath//navigation//NavigationTestSuite.class'
	include '**/somepath//navigation//AccessibilityTestSuite.class'
}
I'm looking to get rid of some deprecation warnings in some of our gradle projects ahead of an upgrade 9.0 (whenever that comes out). We're running Gradle 8.7 currently.
1
Found the issue. We basically have to stop using custom tests altogether and instead use the built-in
test
task and customize it. Documentation here was helpful: https://docs.gradle.org/current/userguide/java_testing.html
v
That you do not have classpath and test classes dir in your snippet exactly is the outstanding issue. You use the conventions set by the Java plug-in and the link shows you how to keep the behavior also with Gradle 9 and get rid of the warning.
s
ahhh sweet, confirmed that those changes got the custom test tasks to work. However, it looks like Gradle does not recommend using custom test classes going forward.
v
Why not?
s
In the docs it reads:
By default, when applying the
java
plugin, the
testClassesDirs
and
classpath
of all
Test
tasks have the same convention. Unless otherwise changed, the default behavior is to execute the tests from the default
test
TestSuite
by configuring the task with the
classpath
and
testClassesDirs
from the
test
suite. This behavior will be removed in Gradle 9.0.
While this existing default behavior is correct for the use case of executing the default unit test suite under a different environment, it does not support the use case of executing an entirely separate set of tests.
If you wish to continue including these tests, use the following code to avoid the deprecation warning in 8.1 and prepare for the behavior change in 9.0. Alternatively, consider migrating to test suites.
I read this as you can get custom test tasks to work by adding
classpath
and
testClassesDirs
, but that Gradle recommends migrating to test suites for more future proofing.
v
Yes and no. If you have different sets of tests like functional tests, unit tests, integration tests, ..., it might be better and easier to use the new test suites feature. If you just want to define separate test task with special configuration, like testing on a different Java version, testing with different environment settings and so on that you want to run in the same Gradle run so cannot just use the same task with different options, creating a custom test task is probably fine. You just have to configure those properties manually now, as this might not make sense for all custom test tasks.
s
Okay that makes more sense. Our use case is for testing functional tests, unit tests, etc. rather than different Java versions or env settings. That said, is there a better way to distinguish which tests you're running other than using filter(s)?
gradle test --tests 'org.name.example.common.*' --tests 'org.name.example.model.*' --tests 'org.name.example.appname.action.*'
v
Plenty
You could for example use test suites as said and thus have the tests also properly separated in different source directories
But depending on the test framework you use, you could for example also tag the tests with some annotation and then select the test to run by that test if you really prefer to have them in one source set
I personally prefer to have them cleanly separated
s
right we have some separate into different directories, and for those we're using
gradle test --tests '**navigation*'*
ahh tagging would be nice, we're using JUnit
v
Well, whatever you prefer. As I said, I prefer to have unit tests in
src/test/...
and functional tests in
src/functionalTest/...
, ...
s
makes perfect sense, I'll chat with my devs and the reorganization appears to be the best approach. Thank you!
👌 1