Open reda-alaoui opened 3 months ago
Create a Custom JUnit 5 Extension: Implement a custom JUnit 5 extension that tags tests with the module name. This extension will automatically add a tag to each test based on the module it belongs to.
Register the Extension as a Service: Create a file named org.junit.jupiter.api.extension.Extension in the src/test/resources/META-INF/services/ directory and add the fully qualified name of your extension class:
Set the moduleName System Property: When running tests, set the moduleName property based on the current module. This can be done via Maven profiles or in your CI pipeline configuration. In your Maven Surefire plugin configuration:
Run Your Tests: When you run your tests in each module, the ModuleTaggingExtension will automatically add a tag to each test with the name of the module.
.....that should help....
On Thu, Aug 22, 2024 at 6:24 PM Réda Housni Alaoui @.***> wrote:
I have a multi maven module project and CI configured to split test executions among multiple groups. To do that, I use property groups of maven-surefire-plugin. I want each test to be tagged with the name of the module it belongs to. For example, all tests of module foo should be tagged @Tag("foo"). Meta-annotations are not good enough because someone will forget to annotate a test class.
Since Extension can be registered as service loaders, it'd be nice to be able to provide the tag information from an Extension.
— Reply to this email directly, view it on GitHub https://github.com/junit-team/junit5/issues/3932, or unsubscribe https://github.com/notifications/unsubscribe-auth/BKVTX4P4WRO4STGGWGLZOBDZSX7C3AVCNFSM6AAAAABM6MPIDOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ4DCMBZHA2TGMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
@MDOluka, it appears that you are using AI to create your responses.
If so, please refrain from doing that, since it does not add value to the discussions.
Hi @reda-alaoui,
Congratulations on opening your first issue for JUnit 5. 👍
Since Extension can be registered as service loaders, it'd be nice to be able to provide the tag information from an Extension.
The Extension
APIs in JUnit Jupiter are applied during the "execution phase"; whereas, tags (configured via the @Tag
annotation) are processing during the "discovery phase".
Consequently, a Jupiter extension cannot provide tags.
The tags sourced from @Tag
are made available via TestTag
instances in org.junit.platform.engine.TestDescriptor.getTags()
. And those are processed in org.junit.platform.launcher.TagFilter
which creates corresponding org.junit.platform.launcher.PostDiscoveryFilter
instances.
Thus, it sounds like you might be able to achieve your goal via a custom PostDiscoveryFilter
which filters out tests that do not "belong to the current module".
See Registering a PostDiscoveryFilter in the User Guide for details and let us know if that suits your needs.
Cheers,
Sam
@MDOluka, it appears that you are using AI to create your responses.
If so, please refrain from doing that, since it does not add value to the discussions.
i read the Junit user guide and also do some research using a.i but not to create responses.
Hi @sbrannen ,
Thus, it sounds like you might be able to achieve your goal via a custom PostDiscoveryFilter which filters out tests that do not "belong to the current module".
I tried to use PostDiscoveryFilter
. But I didn't find a way to access the expression provided by attribute groups
from maven-surefire-plugin
.
My goal is not to make sure only tests of the module run. My goal is to run a full build including all modules and telling which tests should run via tags. I have projects where the same tag will be shared by 2 modules.
If you would like us to be able to process this issue, please provide the requested information. If the information is not provided within the next 3 weeks, we will be unable to proceed and this issue will be closed.
IMHO, the information was provided.
IMHO, the information was provided.
Thanks for the feedback, @reda-alaoui.
In light of that, I am closing this issue.
@sbrannen , sorry, I genuinely don’t understand your answer and the fact you closed the issue without any explanation. Did you miss https://github.com/junit-team/junit5/issues/3932#issuecomment-2306794339?
I apologize: I misunderstood your response to mean that you had sorted things out based on the provide information.
I'll reopen this issue.
I have a multi maven module project and CI configured to split test executions among multiple groups. To do that, I use property
groups
ofmaven-surefire-plugin
. I want each test to be tagged with the name of the module it belongs to. For example, all tests of modulefoo
should be tagged@Tag("foo")
. Meta-annotations are not good enough because someone will forget to annotate a test class.Since Extension can be registered as service loaders, it'd be nice to be able to provide the tag information from an Extension.