The short version of this: it is hard.
When searching for this you inevitable end up on this URL:
This is however more a proposal, and to actually use it you need to use a maven plugin provided by sormuras.
I considered it but:
-
It seems overly complicated
-
Support from IDEs seems missing
This is all about surefire/failsafe plugins. I think they do support module-info shadowing, but it is hard without proper support of IDE. Shadowing should enable whitebox testing (by e.g. giving access to junit framework, to parts of the code that actually should be hidden).
Blackbox testing should in principle be more straightforward. You could simply make a new maven module, and place your tests in an entire new jigsaw module.
All this is a bit annoying, because in every setup I could think of it would give rather a lot of boiler plate code.
-
Place blackbox tests in a directory next to
main
and testtest
. -
Place blackbox tests in a module below the current one.
-
Place blackbox tests in a module next to the current one.
Blackbox testing is less flexible, and I generally considered testing a valid argument for 'white boxing', i.e. e.g. accessing package access methods.
Another annoyance is that these modules may get deployed to a repository, which is pointless.
I arranged via profiles that this is avoided.
Since a long time you can load java services via META-INF/<name of services>.properties In JPMS you can put the service in module-info.java, like so:
module org.meeuw.i18n.countries {
provides RegionProvider with
CurrentCountryProvider,
FormerCountryProvider,
UserAssignedCountryProvider,
UnofficialCurrentCountryProvider,
VehicleRegistrationCodeFallbackProvider
;
}
This however does not seem to work in a test-only module. I haven’t figured out yet why that is, and I’m even unsure if I’m not somehow mistaken here.
It is a bit early to ditch support java 8 entirely. Not everyone is running java 11 already. We certainly aren’t. So for the moment it is decided that:
-
Only
module-info.java
, plus possibly test code, is to be compiled with target java 11. -
The rest of the code is compiled with target java 8.
This is done by some configuration on the maven compiler plugin. The code is actually compiled with java 11, but should be compatible with java 8.