modules and tests
Remi Forax
forax at univ-mlv.fr
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 module-info.java.
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 module-info.java 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.
regards,
Rémi
* here is an executable specification of the merging rules: https://github.com/forax/pro/blob/master/src/main/java/com.github.forax.pro.helper/com/github/forax/pro/helper/ModuleHelper.java#L258
More information about the jigsaw-dev
mailing list