-
Notifications
You must be signed in to change notification settings - Fork 299
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
make tests included via ArchTests
report outer class as test location
#1279
Merged
codecholeric
merged 3 commits into
main
from
make-tests-included-via-ArchTests-report-outer-class-as-test-location
Apr 9, 2024
Merged
make tests included via ArchTests
report outer class as test location
#1279
codecholeric
merged 3 commits into
main
from
make-tests-included-via-ArchTests-report-outer-class-as-test-location
Apr 9, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
codecholeric
force-pushed
the
make-tests-included-via-ArchTests-report-outer-class-as-test-location
branch
2 times, most recently
from
March 27, 2024 14:24
8920f0c
to
fa822f5
Compare
hankem
approved these changes
Apr 4, 2024
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.
LGTM! 👍
With this change, test reports show where ArchTests have been included.
Comparison of old and new result for RuleLibraryTest
:
...t-junit/junit4/src/main/java/com/tngtech/archunit/junit/internal/ArchUnitRunnerInternal.java
Show resolved
Hide resolved
...junit4/src/test/java/com/tngtech/archunit/junit/internal/ArchUnitRunnerRunsRuleSetsTest.java
Outdated
Show resolved
Hide resolved
archunit-junit/junit4/src/main/java/com/tngtech/archunit/junit/internal/ArchTestExecution.java
Outdated
Show resolved
Hide resolved
codecholeric
force-pushed
the
make-tests-included-via-ArchTests-report-outer-class-as-test-location
branch
from
April 9, 2024 21:45
fa822f5
to
a54ca34
Compare
We renamed `ArchRules` to `ArchTests` a while ago to avoid confusion. The renamed methods are some leftovers from the time before this renaming that are now consolidated. Signed-off-by: Peter Gafert <peter.gafert@archunit.org>
So far, if we include rules from other test classes, e.g. ``` @RunWith(ArchUnitRunner.class) @AnalyzeClasses(..) class ExampleTest { @archtest static final ArchTests nested = ArchTests.in(Other.class); } ``` then the nested class (`Other.class` in this case) will be used as test location. This can cause confusion, because by this if `Other.class` is included in two separate test classes, analyzing different locations via `@AnalyzeClasses`, the results will be reported for the same test class `Other.class`. We now set the root class that started the test as the test class of the `Description`. To make it easy to understand through which path a rule is included in more complex scenarios, we extend the display name to include the path of nested classes. Signed-off-by: Peter Gafert <peter.gafert@archunit.org>
So far, if we include rules from other test classes, e.g. ``` @AnalyzeClasses(..) class ExampleTest { @archtest static final ArchTests nested = ArchTests.in(Other.class); } ``` then the nested class (`Other.class` in this case) will be used as test location. This can cause confusion, because by this if `Other.class` is included in two separate test classes, analyzing different locations via `@AnalyzeClasses`, the results will be reported for the same test class `Other.class`. At least for Gradle the reason it picks `Other.class` seems to be that it traverses up the `TestDescriptor` hierarchy and picks the first descriptor with an attached `ClassSource`. We can thus simply not set a `TestSource` for the intermediary descriptors, i.e. the container descriptors caused by `ArchTests.in(..)`, and by that make Gradle traverse up until it finds the root that started the test. To make it easy to understand through which path a rule is included in more complex scenarios, we extend the display name to include the path of nested classes. Signed-off-by: Peter Gafert <peter.gafert@archunit.org>
codecholeric
force-pushed
the
make-tests-included-via-ArchTests-report-outer-class-as-test-location
branch
from
April 9, 2024 22:18
a54ca34
to
e658be0
Compare
codecholeric
deleted the
make-tests-included-via-ArchTests-report-outer-class-as-test-location
branch
April 9, 2024 22:36
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So far, if we include rules from other test classes, e.g.
then the included class (
Other.class
in this case) will be used as test location.This can cause confusion, because by this if
Other.class
is included in two separate test classes,analyzing different locations via
@AnalyzeClasses
,the results will be reported for the same test class
Other.class
.We now report the outermost class that started the test (the one with `@AnalyzeClasses)
as the test location for both JUnit 4 and JUnit 5.
To make it easy to understand through which path a rule is included in more complex scenarios,
we extend the display name to include the path of nested classes.
Resolves: #452