-
-
Notifications
You must be signed in to change notification settings - Fork 765
Draft: Testing Module Testing with Maven for #2760 #2773
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
Conversation
Adding an own module for testing in the modular world.
|
Hi Simon, thanks for the PR! This probably overlaps with #2759, which is already stable from the Maven perspective but:
|
This is a cool point I didn't consider yet: it would be much better to re-run our entire test suite in the modular world instead of adding dedicated tests for it. |
yes it does, sorry I did not see that one :)
I added one specially for this case within this pr.
maybe somebody has suggestions for this error |
Are you getting this error in the IDE or with Maven? I'll try to play with it as well this evening. |
|
I pushed the changes to use a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still checking what could be done in this area. Below are just a few comments but feel free to ignore them until it's clear where we want to go.
About these errors:
the unnamed module reads package org.assertj.core.api from both assertj.core and org.assertj.core
I believe this is caused by these three actors:
- The
assertj-coremulti-release JAR with thismodule-info - The
assertj-coretest JAR that has no module descriptor so it becomes an automatic module - The
assertj-core-moduletestwith themodule-infoundersrc/test/java
I assume the unnamed module in the error message is 3, while assertj.core corresponds to 2 and org.assertj.core corresponds to 1.
I believe the assertj-core test JAR should be created with a descriptor, but right now I believe that having a test JAR would be a backup option (see #2347 for the rationale).
I'm trying another strategy with the branch of #2759:
- Setting the
project.build.testSourceDirectoryto../../../assertj-core/src/test/java - Defining an additional execution of the
maven-compiler-pluginwhere themodule-infoundersrc/test/javagets compiled
This should work when running the maven-surefire-plugin under the assertj-core-module-path module (I'm fixing now the necessary declarations in the local module-info).
Also, it requires a bit of duplication for all the test scoped dependencies of assertj-core and the assertj-core/src/test/java folder is detected by IntelliJ as a test source root for two separate modules, leading to weird IDE errors about imports.
I'm still 100% sure it's the direction we want to take, might be OK but I still need to digest the idea 🙂
Lastly, we'll soon start the development of AssertJ 4 which will drop the multi-release configuration, hopefully simplifying the overall test setup, so we might stay with a basic setup in the 3.x branch to be used ad-hoc for specific investigations.
assertj-core/pom.xml
Outdated
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>test-jar</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, we'd like to avoid the creation of the test jar, see #2347. If we are really forced to have it, we should prevent its deployment to the Nexus.
| <maven.compiler.release>${java.version}</maven.compiler.release> | ||
| <maven.compiler.source>${java.version}</maven.compiler.source> | ||
| <maven.compiler.target>${java.version}</maven.compiler.target> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
java.version should be enough, all of them are set in assertj-parent
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <version>3.0.0-M7</version> | ||
| <!-- <configuration>--> | ||
| <!-- <dependenciesToScan>--> | ||
| <!-- <dependency>org.assertj:assertj-core:test-jar</dependency>--> | ||
| <!-- </dependenciesToScan>--> | ||
| <!-- </configuration>--> | ||
|
|
||
| </plugin> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless there is a special config for the two plugins, declaration is not necessary as we get already the latest versions from assertj-parent
| <bannedDependencies> | ||
| <!-- <bannedDependencies> | ||
| <includes> | ||
| <include>*:*:*:jar:test</include> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we would need to use a test-jar dependency, we could relax this condition while keeping the enforced scope:
| <include>*:*:*:jar:test</include> | |
| <include>*:*:*:*:test</include> |
|
I tried the path you want to use, I did not manage to get it to compile. Not sure why but test compile took ages ;) I even abused the approach from the mutli release jar and patched the jar with a module-info out of the Modulartest module. But as said I had some kind of compile issues, as it tool ages and I was too impatient to wait more than 5 minutes. I will also try to experiment some more in the evening. Looks really interesting.
Be aware to also set the test resources ;) |
|
I've pushed my WIP changes in e138460, I'll try to finalize them later in the day. |
aa9301f to
bd71c07
Compare
|
i used part of your code, and I figured out it is just hamcrest - by adding the optional junit dependency and excluding hamcrest, I made it work locally :) with your testdirectory approach. i will check later again, but it looks promising There are tests failing currently due to missing resources, which I will check later |
461a993 to
dd3a2db
Compare
|
please do not be overwhelmed by my recent changes I discovered an issue with all files which have been accessed during the test, as the path was always module specific and not loaded via resources, i adapted the tests to do so (most likely there is a good reason for that, i just thought a fast replace in the IDE could do the trick to see which errors are left) now i am left with 6 errors, and one of those is my test for those methods. strangely enough there has not been a lot of other detections regarding package violations, except the deepdifference tests. I know, those changes are now a lot and blew up the whole PR, and they might not be desired, this was again just exploration and fact finding. So please if you do not see those fitting the need, ignore them :), but we would need to find another solution for the tests and the resources. (most likely also doable by switching the working directory) .. and I always have to run a clean, before I can run the modular tests |
|
Thank you so much for taking the time to do this already! I'm using your attempts as inspiration and I'm also trying to take a slightly different direction to avoid the weird IDE behavior I was mentioning: instead of setting I'm not sure how much time I'll have in the next days but I'll continue on this topic as soon as I can. |
|
if I can support you somehow further, or if there is anything I should test/do, etc. please let me know :) I am glad if I can help you. |
|
just something which popped to my head, instead of recompiling the tests why not just reuse the compiled files? this way the test is executed faster, and it should actually not cause any problems? see 1d1af6f Downsides:
Ups:
|
|
also an interesting twitter thread regarding this topic: https://twitter.com/lukaseder/status/1389236184472301583 |
Thanks! I think I've seen it last year and I agree especially with:
which is somehow the strategy I'm trying to use with #2424. It might be we'll go with the approach of moving all the tests to a separate module. I need to digest the idea a bit more 🙂 |
|
One more thought: I'm not really thrilled to move tests to a separate module-based artifact until IDEA-301032 is fixed, otherwise it will be an unpleasant experience for contributors using IDEA (myself included 😄). |
301ca01 to
c730d18
Compare
|
Superseded by #3771. |
Sorry i simply started experimenting out of curiosity regarding #2760 , and I want to share what I tried and what worked and did not work for such modular tests. Please just close this pr, if you do not think it is fitting. Although if you think, this needs just polishing, let me know, i can adapt and help to make it better.
This pr works, but only has one test - so theoretically it is usable :)
BUT... i wanted to experiment a little bit more, and maybe make the original unit tests work within this modular module.
test-jar approach
I tried adding following to the assertj-core to generate a test jar
and tried to apply it as a dependency within my modular test. Sadly this ended up with a lot of package errors
errors
additional source directory
Then i thought maybe extracting them into
target/test-classescould also do the trick - sadly notThen i thought maybe i could simply add the test source directory to the modularTest module, but this somehow needed more than 5 minutes and did not finish, so i also stepped away from this approach.