modules and tests

Remi Forax forax at
Thu Nov 24 08:46:29 UTC 2016

We already have discussed how to do testing in the new modular environment, but i'm not satisfied by the current state (but maybe i'm wrong).

Here, i will focus on unit testing, which is the most intrusive kind of testing.

Historically, unit testing was easy because you can have several source directories (src and test) containing the same package, note that this doesn't create split packages, because during the compilation, the classes inside src and test are compiled together and later executed together. Having a separation between a folder containing the sources and the on containing the tests allow to produce two jars, one based only on sources and one based on the merging between the sources and the tests. Because the tests can have dependencies not needed by the sources (think junit.jar by example), the classpath when compiling and running the sources and the tests was slightly differents, the classpath of the test having more dependencies.

Now, we have introduced modules and modules define their own dependencies. At compile-time/runtime, source and test have to be in the same module otherwise, there will be a gap between the sources environment and the test environment. So like before, the idea is to generate two jars, representing the same module. Also, because sources and tests do not have exactly the same dependencies, the source folder and the test folder should have their own
But when compiling the test, javac raises an error, because it doesn't allow to have two module-info files. I believe this is a bug that should be fixed.

It's not obvious at it seems, it requires javac to be able to merge several into one, and because the module descriptor allows to restrict exports or opens, the merging rules* as to be specified.

But i think we should support modules AND tests by default as we have done since more than 20 years.


* here is an executable specification of the merging rules:

More information about the jigsaw-dev mailing list