How do you organize tests in a modular Java project?

后端 未结 1 936
耶瑟儿~
耶瑟儿~ 2020-12-03 08:46

I am creating a modular build (using module-info.java) on GitHub, but when adding a module-info.java to the modules that I want modular, no tests can be executed...

相关标签:
1条回答
  • 2020-12-03 09:12

    Welcome to Testing In The Modular World!

    Which kind of tests do you want write?

    Extra-module tests: Create a test-only project (no "src/main" directory) and declare a "src/test/java/module-info.java" module descriptor.

    In-module tests: As it was from Day 1 you need to "blend in"/merge/shadow your test classes into your main classes or vice versa. Here you have mainly two ways to achieve this:

    • "compile modular main sources" and "patch plain test sources" at test-runtime with some additional "JVM options hacking the Module system" to execute tests.
    • "compile modular test sources" and "patch modular main sources" at compile-time to execute tests.

    Blog

    https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world

    Examples

    • Work-in-progress blueprint https://github.com/sormuras/sandbox/tree/master/sors-modular-testing-blueprint

    • Integration tests starting with "modular-world-" at https://github.com/sormuras/junit-platform-maven-plugin/tree/master/src/it

    Background and other resources

    • https://github.com/junit-team/junit5-samples/tree/master/junit5-modular-world
    • https://github.com/forax/pro
    • https://blog.codefx.org/java/five-command-line-options-to-hack-the-java-9-module-system/
    0 讨论(0)
提交回复
热议问题