Skip to content

Docs. Troubleshooting test run configuration with Java 17 #2047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alisevych opened this issue Mar 27, 2023 · 6 comments
Closed

Docs. Troubleshooting test run configuration with Java 17 #2047

alisevych opened this issue Mar 27, 2023 · 6 comments
Assignees
Labels
ctg-documentation Improvements or additions to documentation ctg-enhancement New feature, improvement or change request

Comments

@alisevych
Copy link
Member

alisevych commented Mar 27, 2023

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

@alisevych alisevych added ctg-documentation Improvements or additions to documentation ctg-enhancement New feature, improvement or change request labels Mar 27, 2023
@alisevych alisevych added this to the Upcoming Release milestone Jul 6, 2023
@alisevych
Copy link
Member Author

@olganaumenko
Copy link
Collaborator

@alisevych Please check the Troubleshooting section in Wiki.

@alisevych
Copy link
Member Author

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.

@olganaumenko
Copy link
Collaborator

@alisevych Please verify the fix.

@github-project-automation github-project-automation bot moved this from Todo to Done in UTBot Java Sep 25, 2023
@alisevych
Copy link
Member Author

alisevych commented Sep 28, 2023

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"]

@alisevych alisevych reopened this Sep 28, 2023
@github-project-automation github-project-automation bot moved this from Done to In Progress in UTBot Java Sep 28, 2023
@alisevych
Copy link
Member Author

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"``

@alisevych alisevych self-assigned this Oct 2, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in UTBot Java Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-documentation Improvements or additions to documentation ctg-enhancement New feature, improvement or change request
Projects
Archived in project
Development

No branches or pull requests

2 participants