Closed BoukeNijhuis closed 4 weeks ago
I think this needs to remain in the main part of the project so it is exposed for downstream projects that want to leverage it in their own tests.
@checketts is right. By having this, when you write a @WebMvcTest, then the autoconfiguration is automatically also applied. So I think it would be good to also add this to your dynamic-version-url
project so the web tests also automatically have the correct configuration.
Thank you for your replies and for showing how autoconfiguration works. It really improved my project.
Just to be sure: my point is that this file should be in the TEST folder and not in MAIN folder, because it is used for tests. You should not need it for production. In my project I put it in the test folder and it still works properly.
@checketts thinks it is on purpose in the MAIN folder. If this is the case, please close this issue.
It is in the MAIN folder so it get included in final jar. That mean in my project that pulls in htmx-spring-boot
as a dependency can leverage the auto configuration in my project's tests.
If it is in the TEST folder, then it won't be included in the htmx-spring-boot
jar and my project won't be able to leverage it.
There could be a separate htmx-spring-boot-testing
module for this purpose, but I don't think it would be worth adding the potential complexity/confusion for users.
In my project I put it in the test folder and it still works properly
Did you try to build a JAR of your library and then write an @WebMvcTest
in a separate project that imports the library via Maven or Gradle? Was the autoconfiguration picked up running the test? Normally, as far as I know it will not.
Totally clear why the test file is in the main folder. Thanks for explaining. I am closing this issue.
When fixing this isse I used this project as an example.
I noticed that there is a test file in the main folder:
htmx-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc.imports
This file can be moved to the test folder and this way the production code is cleaner.
Example: https://github.com/BoukeNijhuis/dynamic-version-url/blob/main/src/test/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc.imports
Thanks again for taking the time to create an issue on my project.