[ 
https://issues.apache.org/jira/browse/SUREFIRE-1811?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17147423#comment-17147423
 ] 

Christian Stein commented on SUREFIRE-1811:
-------------------------------------------

* module-info.*java* in *src/main/java* of a Maven project is part of the 
"public/published/deployed" artifact generated by Maven. That one, transformed 
into a compiled module descriptor, defines the API of this Java module. It 
should (read: must) never ever contain directives that only exist to satisfy 
testing needs. All other modules listed in this text are only defined for 
internal purposes, namely testing.
 ** module org.astro
 ** exports org.astro;

 

____ Reminder that everything below this line is not meant to be part of the 
public API –  modules defined below are never uploaded to Maven Central _____

 
 * There should be an *extra-modular* test module-info.*java* in 
*src/test/java* with a different name that reads the "main" module defined 
above. That test module uses the default/official Java module syntax – and is 
best kept in a Maven module next to "main" one with the publish plugin 
disabled. It is the first client of the "main" module defined above. It checks 
the API of the main module. That test module may contain directives that 
satisfy testing needs. Here are some testing-related directives of a test 
module:
 ** requires _main modules defined above_; // use public API of _main module 
defined above_
 ** requires org.junit.jupiter; // use public API of JUnit's modules
 ** requires org.assertj.core; // use public API of AssertJ's modules
 ** ...
 ** open foo to org.junit.platform.commons; // JUnit needs to reflect for @Test 
and other annotations.

 
 * There should be a *in-module* test module-info.*java* in *src/test/main* 
with the same name as the "main" module defined above. This keeps the author of 
the tests in control – and doesn't rely on heuristics applied by build tools. 
That test module reads a like a join of the "main" module defined above and the 
test module of the former bullet point:

 ** module org.astro
 ** exports org.astro;
 ** ...
 ** requires org.junit.jupiter; // use public API of JUnit's modules
 ** requires org.assertj.core; // use public API of AssertJ's modules
 ** ...
 ** open foo to org.junit.platform.commons; // JUnit needs to reflect for @Test 
and other annotations.

 
 * Note: main and test classes are also joined with "--patch-module" here. (The 
"class-path" does join magic implicitly for packages, btw.) The 
maven-compiler-plugin supports this command line flag for test sources since 
over [two 
years|[https://github.com/apache/maven-compiler-plugin/commit/8b26d493760f2b884feec0366f29e57fb6348e06]].

Now, enter the workaround that effectively let tests run on the class-path with 
most test invoking tools and doesn't mess-up IDEs:
 * module-info*.test* is just a text file with official java command line 
options – it's a proposal for test invoking tools not to re-invent wheels. Find 
more details here: 
[https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world]

> Add resources to JPMS test module
> ---------------------------------
>
>                 Key: SUREFIRE-1811
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1811
>             Project: Maven Surefire
>          Issue Type: New Feature
>          Components: Maven Failsafe Plugin
>    Affects Versions: 3.0.0-M5
>            Reporter: Pavel_K
>            Priority: Major
>
> I am testing version 3.0.0-M5 with two module-info in one project - one main 
> and one for test. My test project is here 
> https://github.com/PashaTurok/hibernate-h2-test4 . The problem is with 
> resources. For example, I have  src/main/resources/META-INF/persistence.xml 
> file that is not copied to test module. Because of this it is not possible to 
> find resource in test module and it is necessary to use something like this 
> https://github.com/PashaTurok/hibernate-h2-test4/blob/292e2e683ad72487cbf8d2e5a35dde0d9255001a/src/test/java/com/foo/hibernate/h2/test4/TestIT.java#L72
>  . 
> In target/test-classes/META-INF/jpms.args I see:
> {code:java}
> --patch-module
> my.project=/home/..../hibernate-h2-test4/src/main/java, 
> /home/.../hibernate-h2-test4/target/generated-sources/annotations
> {code}
> As I understand test module will NOT contain resources from the module under 
> test? I mean that test module will NOT contain 
> /home/..../hibernate-h2-test4/src/main/resources? 
> That's why I suggest to include src/main/resources in test module.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to