Skip to content

Docs. Troubleshooting test run configuration with Java 17 #2047

Description

@alisevych

Description

Add Troubleshooting section in User guide on how to run tests with Java 17 using reflection.
In order to support user with bug

Please consider the best place for Troubleshooting section.

Expected behavior

UnitTestBot sometimes cannot combine Object assemble model without using reflection.
Sometimes a private field needs to be set or got.
Reflection methods using setAccessible is forbidden in Java 17+.
User can add keys to the JVm in order to run the tests.
Otherwise UtUtils methods can fail.

Environment

IntelliJ IDEA Ultimate 2023.3.*

Potential alternatives

Possibility to add needed keys automatically can be very complex.
One can see the list of keys needed to run tests for UnitTestBot: build.gradle.kts

Context

UnitTestBot plugin will be working on Java 17 starting from Release 2023.3

Activity

  1. added this to the Upcoming Release milestone on Jul 6, 2023
  2. alisevych commented on Sep 19, 2023

    @alisevych
    MemberAuthor
  3. olganaumenko commented on Sep 20, 2023

    @olganaumenko
    Collaborator

    @alisevych Please check the Troubleshooting section in Wiki.

  4. alisevych commented on Sep 20, 2023

    @alisevych
    MemberAuthor

    I would correct the following wording not to mess the user:

    build an Object assemble model to just build an Object

    Also the keys in the first part can be joined into one String so that it can be easily copy-pasted.

  5. olganaumenko commented on Sep 20, 2023

    @olganaumenko
    Collaborator

    @alisevych Please verify the fix.

  6. alisevych commented on Sep 28, 2023

    @alisevych
    MemberAuthor

    We've just identified that adding VM options to Run configuration doesn't work for Gradle run configuration in IDEA.

    In case of Gradle project with JDK 17 and a test that uses reflection, the user needs to configure the task that runs this test.
    Add VM options to the test task in build.gradle file, like following:

    image

    Text to insert:

        jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED", 
                    "--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED"]
    
  7. moved this from Done to In Progress in UTBot Javaon Sep 28, 2023
  8. alisevych commented on Sep 29, 2023

    @alisevych
    MemberAuthor

    The list of modules to open can be different.
    User needs to open the java modules, which their classes are in.

    For example, in OwnerControllerTest in spring-petclinic, there is setFiled called for java.util.LinkedHashMap
    The following exception message is in console:

       java.lang.reflect.InaccessibleObjectException: Unable to make field transient java.util.LinkedHashMap$Entry
    java.util.LinkedHashMap.head accessible: module java.base does not "opens java.util" to unnamed module ...

    So the following string should be added to VM options:
    `"--add-opens", "java.base/java.util=ALL-UNNAMED"``

  9. self-assigned this
    on Oct 2, 2023
  10. moved this from In Progress to Done in UTBot Javaon Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

ctg-documentationImprovements or additions to documentationctg-enhancementNew feature, improvement or change request

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions