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

Nils Renaud commented on SUREFIRE-1909:
---------------------------------------

Hi there,



I'm currently having the same issue as [~c...@newsclub.de] trying to modularise 
my existing application.

Currently all proposed solutions are not good enough to my requirements : 
 - ["official surefire 
solution"|https://maven.apache.org/surefire/maven-surefire-plugin/examples/jpms.html]
 to have unit tests in a dedicated JPMS module requiring the {{my.module.main}} 
module
 -- I can't test "{{{}package private"{}}} methods or classes. {+}I don't want 
to change my code visibility to be able to test it{+}.


 - A variation of this solution could be to set package private classes/methods 
as public and to move them to a package "{{{}exported ... to 
my.module.test{}}}" :
 -- Still +this is really painful with a big codebase+ and introduce a link to 
maintain between main and test modules.


 - To update all Junit test methods visibility to "public" : 
 -- As stated by [~c...@newsclub.de] +this is considered as violation by PMD+ 
and some other static analysis tools. I tend to agree with them and would like 
to follow JUnit 5 standard (plus it's an easy trap, I felt into !)

So I really feel the need to have that handled by the Surefire plugin, have you 
started a PR somewhere [~c...@newsclub.de] ?

Is there any current work on this topic since July 2021 ?

> Support JUnit 5 reflection access by changing add-exports to add-opens
> ----------------------------------------------------------------------
>
>                 Key: SUREFIRE-1909
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1909
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: JUnit 5.x support
>    Affects Versions: 3.0.0-M5
>            Reporter: Christian Kohlschütter
>            Priority: Major
>         Attachments: surefire-jpms-bug.tar.gz
>
>
> Testing JUnit 5 classes of a JPMS-enabled project with Surefire may fail if a 
> test class (or, for example, an abstract test base class) is not declared 
> "public". I'm seeing the following error:
>  
> {code:java}
> java.lang.reflect.InaccessibleObjectException: Unable to make public static 
> void some.package.SomeClass.setupClass() throws java.io.IOException 
> accessible: module some.module does not "opens some.package" to unnamed 
> module @754ba872{code}
> This could be fixed by adding the recommended "{{opens some.package}}" to the 
> project's module-info.java, however that is undesirable since it changes the 
> project's behavior beyond just unit testing. Adding a secondary "test-only" 
> module-info.java is also counterproductive since not all IDEs support this, 
> and these two files would have to be kept in sync, which is non-trivial.
> An easy fix would be to change the "{{--add-exports-}}" VM parameter that 
> surefire adds automatically to "{{-}}{{add-opens}}" in 
> {{maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfiguration.java}}
> This bug is particularly bad because PMD now specifically complains about 
> junit5 classes marked as public instead of package-private; see 
> [https://pmd.github.io/2021/05/29/PMD-6.35.0/]



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to