Skip to content
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

support executing single @ArchTest members #1280

Merged
merged 3 commits into from
Apr 10, 2024

Conversation

codecholeric
Copy link
Collaborator

Currently there is no convenient way to execute a single @ArchTest rule of a test running with JUnit 4 or 5 support.
As a simple mitigation we now provide the possibility to filter a single test via archunit.properties / system property.
This change allows to e.g. pass

-Darchunit.junit.testFilter=rule_field_one,rule_field_two

to a test run, which will then filter the tests and only run the @Archtest fields or methods with the given name(s).

For now we don't support any wildcards or narrowing the match down by surrounding class name
to see if this feature is even missed by users. Basic filtering for classes or packages should already be supported
by the respective test launcher (i.e. both JUnit 4 and 5 support should respect filter requests for classes or packages already).

Issue: #641

Copy link
Member

@hankem hankem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

I noticed that this junit.testFilter does not allow us to distinguish @ArchTests defined as fields and @ArchTests defined as methods, which could have the same member name, but that's probably not needed in practice.

Right now the ArchUnit website can't be started locally anymore,
because Jekyll throws an error

```
 Conversion error: Jekyll::Converters::Scss encountered an error while converting 'assets/css/main.scss': Broken pipe
```

From what I found online Jekyll 4 has become stricter in some way.
I don't exactly understand why, because the scss file still seems to conform to the docs,
but since I also found that GitHub pages uses Jekyll 3.9.5 at this time anyway,
I figured we may as well just downgrade to that version,
which then also fixes our problem.

I don't remember the original reason why we weren't using the github-pages Gem,
but from what I see right now it seems to work exactly as specified in the docs.
It also fixes Jekyll to the correct version.
So, I reverted the Gemfile to use the github-pages Gem instead of the jekyll Gem.

Signed-off-by: Peter Gafert <peter.gafert@archunit.org>
One inconvenience of the current state of the `ArchUnitTestEngine`
is the fact that there is no simple way to execute a single rule.
For methods annotated with `@ArchTest` this might be supported by the IDE,
but for fields there is no convenient way except of commenting all other `@ArchTest` annotations.

We now provide a simple way to run any member in isolation
by specifying a system property / `ArchConfiguration` value.
This change allows to pass a simple test name filter
that for now only supports exact member matches.
E.g. specifying `-Darchunit.junit.testFilter=my_custom_rule` would run the rule
declared in a field or member with name `my_custom_rule`.
Multiple members can be joined by `,` and are then all executed in one run.

Signed-off-by: Peter Gafert <peter.gafert@archunit.org>
One inconvenience of the current state of the `ArchUnitRunner`
is the fact that there is no simple way to execute a single rule.
For methods annotated with `@ArchTest` this might be supported by the IDE,
but for fields there is no convenient way except of commenting all other `@ArchTest` annotations.

We now provide a simple way to run any member in isolation
by specifying a system property / `ArchConfiguration` value.
This change allows to pass a simple test name filter
that for now only supports exact member matches.
E.g. specifying `-Darchunit.junit.testFilter=my_custom_rule` would run the rule
declared in a field or member with name `my_custom_rule`.
Multiple members can be joined by `,` and are then all executed in one run.

Unfortunately, filtering in JUnit 4 is tied to only the `Description` of the current test.
Since we don't want to couple text parsing of the description to filtering
(e.g. if we change the description in the future),
we have to introduce a hack to transmit the original member name to the `Filter`.
Due to the fact that `Description` is effectively final and has no intended way for our
use case, we (ab-)use the `annotations` of the test member to pass along the information
in a custom annotation. This should have no further effect, since no infrastructure can
react to unknown annotations, which may be present at any time for given tests.

Signed-off-by: Peter Gafert <peter.gafert@archunit.org>
@codecholeric
Copy link
Collaborator Author

I noticed that this junit.testFilter does not allow us to distinguish @ArchTests defined as fields and @ArchTests defined as methods, which could have the same member name, but that's probably not needed in practice.

Yes, I was aware of that, but as you wrote, I doubt that will really be a problem in practice. If it is, we can still ponder about making this more powerful. But, let's see first if there are really requirements for this...

@codecholeric codecholeric force-pushed the support-executing-single-archtest-field branch from 5f81e5c to 14d7f4d Compare April 9, 2024 23:27
@codecholeric codecholeric merged commit 23c483b into main Apr 10, 2024
21 checks passed
@codecholeric codecholeric deleted the support-executing-single-archtest-field branch April 10, 2024 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants