-
Notifications
You must be signed in to change notification settings - Fork 75
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
Undocumented error message that is possibly wrong. #868
Comments
As mentioned in #867, I don't have much experience running EqualsVerifier as a module. However, EqualsVerifier uses reflection to modify the class that you're testing, and also all of its dependencies. Therefore, they must all be open for reflection, at least for the purporses of EqualsVerifier. Or you can provide instances of this class (VariableManager) via .withPrefabValues(). I agree that I should probably add this to the list of error messages on the website. |
For the case the the module path is the problem I have two ideas:
|
I'm able to reproduce the problem, but I don't know how to solve it yet. I've added a simpler class to your project, in the same package as the TemplateEngine: public class Point { That results in So adding prefab values for the fields of the class won't help, the class under test itself must also be open to EqualsVerifier. For now I can offer you only two workarounds:
Before you opened this ticket, I was already looking into two things: |
For the case the the module path is the problem I have two ideas:
|
For me I will go with workaround option 2, because to my best knowledge option 1 is not an option, because the classpath applies to be deprecated - or did they revert this? Btw. you are not the only one with job and family ;-) Today its the birthday of one of my grandchilds ;-) |
I wouldn't say that the classpath is deprecated, far from it. Although it might be good to look to the future. I've encountered many projects that use modules, but yours is the first that also runs the tests as modules. That said, I can't find in your parent pom how you set that up. Can you maybe show me where to look exactly so I can reproduce this in a smaller test project? Congrats for your grandchild! |
JUnit Pioneer also runs tests on the module path and uses EqualsVerifier 🙂 |
@scordio That's awesome! 😃 Can you point me to the relevant portion of the build script that makes the tests run on the modulepath? |
Probably https://github.com/junit-pioneer/junit-pioneer/blob/main/build.gradle.kts#L223-L233 (paging @Michael1993 and @beatngu13) Also, have you seen Testing In The Modular World from @sormuras? |
I have read something he wrote on the subject, but I'm not sure if it was that one. Like like a great reference though, I'll be sure to read it when I have some time. And now you mentioned it, he even offered to help in one of the other open tickets. And there aren't even that many. I feel slightly ashamed now 🙈😅 But also more motivated to finally get this module stuff straightened out... |
Still here. Happy to help. 🤓 |
I don't know what you are searching for in the parent pom, but there is only a small special about module testing. It still works using the maven surefire plugin. The only special thing I know about is that within src/test/java you could place a module-info.test that will replace (done by surefire) the module-info.java file during testing. |
I don't know if that helps but there is the following article about modules (in German language) from oracle: Maybe there is a translation or google translate might help. The interesting part (at the end) is that you might need to use "setAccessible" in your code - after my module has been defined to be open - or only the internal package has to be defined as opens. |
Transation: Reflection defaults By default, a module with reflexive runtime access to a package can see the package's public types (and their nested public and protected types). However, code in other modules can access all types in the specified package and all members within those types, including private members via setAccessible, as in previous versions of Java. For more information about setAccessible and reflection, see Oracle's documentation. |
Thanks @sormuras ! 😄 If I read your text correctly, and @PowerStat's comments and code, then there only thing I have to do is add a In that case, I suppose I could spin off a new Maven submodule, add a If so, I could do some experimenting there, learn the module system by doing, and determine how I should update the documentation. Then I can introduce a proper |
Or will putting a |
I've had some time to play around with your project, @PowerStat , and I found a few things. Note, first, that I'm running the tests using Maven, not from IntelliJ.
Even when moving the EqualsVerifier test to the same package as the class it verifies, and even with the prefab values, I had to add these lines to the
I would have expected that adding prefab values for some of the fields would work too, instead of opening up the package. Haven't been able to figure out why, yet. To be continued! TL;DR for @sormuras : do you know if |
Yes. It's a total different thing for non-official feature. Only some test plugins (for build tools) support it. Which means, official tools like |
Ah, thanks for clarifying. In @PowerStat's project, Also, if I provide a |
OK, should have read @sormuras's post more closely instead of just skimming it, all of my questions were answered: yes, @PowerStat, to fix your project, here's what you should do. Rename your open module de.powerstat.phplib.templateengine { // Note the 'open'
// requires java.io;
// requires java.nio;
// requires java.util;
requires org.apache.logging.log4j;
requires org.junit.jupiter.api;
requires com.github.spotbugs.annotations;
requires io.cucumber.java;
requires org.junit.platform.suite;
requires io.cucumber.junit.platform.engine;
requires net.bytebuddy; // A dependency for EqualsVerifier
// for some reason, it's not needed to add requires nl.jqno.equalsverifier;
} That should do it. I'll assign myself some homework too.
@PowerStat, thanks for providing me with a nice rabbit hole to dive into over this weekend, and @scordio and @sormuras, thanks for helping me climb out of it again :). |
@jqno Sorry for beeing away for some days, but I try to answer open questions here:
to my module-info.test is something I have expected. Or opening the complete module.
|
|
@jqno |
Ouch - I wish you good luck with that. Hope it's not too much work to sort this out! |
@jqno |
I think the split package issue occurs when two different modules export classes in the same package. But in this case, it's the same module, as |
@jqno: I only hat the *.test packages in mind - that was the one of the reasons I put the tests into extra subpackages - to avoid having split packages when not integrating the main src with the test src ;-) |
I've just released version 3.15.3, which improves the readability of the error messages. I'll now close this issue. If you have any other problems or questions, don't hesitate to open a new one! And good luck with the changes! |
Describe the bug
I have a small opensource project here on which I use the equalsverifier first:
https://github.com/PowerStat/TemplateEngine
After adding it (not commited yet) I got the following error message:
[ERROR] Failures:
[ERROR] TemplateEngineTests.equalsContract:1966 EqualsVerifier found a problem in class de.powerstat.phplib.templateengine.TemplateEngine.
-> Unable to make field private final java.util.Map de.powerstat.phplib.templateengine.intern.VariableManager.vars accessible: module de.powerstat.phplib.templateengine does not "opens de.powerstat.phplib.templateengine.intern" to unnamed module @44a7bfbc
For more information, go to: https://www.jqno.nl/equalsverifier/errormessages
(EqualsVerifier 3.15.2, JDK 17.0.8 on Windows 10)
The point is the "intern" package should not be visible o the outside. I also can't see a bug here that could explain this - but maybe I am overseeing something?
Also the message is not documented on the mentioned errormessages page.
To Reproduce
Checkout my repo, add "requires nl.jqno.equalsverifier;" to the "module-info.test".
Add
"<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.15.2</version>
<scope>test</scope>
</dependency>" to the pom.xml
Modify the TemplateEngineTests.java:
Add:
@test
public void equalsContract()
{
EqualsVerifier.forClass(TemplateEngine.class).verify();
}
Add:
@disabled("EqualsVerifier")
to testHashCode() and testEquals()
Do "mvn clean test".
Code that triggers the behavior
See above
Error message
See above
Expected behavior
No error message and everything is ok.
Version
See above: 3.15.2
Additional context
Java 21 is also installed on my system.
The text was updated successfully, but these errors were encountered: