You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Christian Kohlschütter (Jira)" <ji...@apache.org> on 2021/04/22 02:44:00 UTC
[jira] [Updated] (SUREFIRE-1909) Support JUnit 5 reflection access
by changing add-exports to add-opens
[ https://issues.apache.org/jira/browse/SUREFIRE-1909?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Christian Kohlschütter updated SUREFIRE-1909:
---------------------------------------------
Description:
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}}
was:
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}}
> 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
>
> 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 message was sent by Atlassian Jira
(v8.3.4#803005)