How can I test a service provider implementation module with Junit 5?

前端 未结 2 1618
名媛妹妹
名媛妹妹 2021-01-25 05:16

This is my base module which needs implementations of interfaces defined in myspi package. Various providers can offer MyProvider implementations. Base module uses them via mysp

2条回答
  •  爱一瞬间的悲伤
    2021-01-25 05:48

    Basically you're on the right track. You need to convince the Java module system that your test modules are the single source of thruth when it comes to resolve modules are test runtime.

    Black-box testing is easy.

    White-box testing in the modular world, meaning testing protected and package private members within a module, is tricky. There are at least two ways to achieve this: a) use java command line options to configure the Java module system at test startup or b) blend main sources into the test sources at compile time and maintain a dedicated module-info.java in your test sources.

    Please visit the links to the blogs and examples posted over at How to make a modular build with jdk > 1.8 Here is an excerpt for convenience:

    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/

    And expect most IDE to not support you either. For now.

提交回复
热议问题