GeezerVison is showing github.com — [java] MethodNamingConventions - Add support for JUnit 5 method naming by birdflyer-lszo · Pull Request #2476 · pmd/pmd
Conversation
birdflyer-lszo
commented
May 11, 2020
•
edited by adangel
Loading
Uh oh!
There was an error while loading. Please reload this page.
Rule: MethodNamingConventions
Provide a junit5TestPattern property that allows customisation of test method naming in JUnit 5 tests.
The motivation behind this PR was to allow method naming conventions for JUnit5 style tests. These can be annotated using the org.junit.jupiter.api.Test. The current implementation is checking for the JUnit 4 annotations (org.junit.Test) only.
I discovered this because we are using the Osherove naming pattern for our JUnit 5 tests and therefore need to allow additional characters (namely underscores) in the method names. After setting the JUnit 4 style pattern, I simply noted that these were not applied.
Ready?
- Added unit tests for fixed bug/feature
- Passing all unit tests
- Complete build
./mvnw clean verify passes (checked automatically by travis)
- Added (in-code) documentation (if needed)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Tests that are annotated with org.junit.jupiter.api.Test were not
recognized as unit tests.
Provide detection for JUnit 5 style tests and also provide the possibility
to customize the method naming regex similar to the existing ones.
birdflyer-lszo
changed the title
Feature/junit5 method naming
[java] MethodNamingConventions - Add support for JUnit 5 method naming
May 11, 2020
ghost
commented
May 11, 2020
•
edited by ghost
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
1 Message
|
| 📖 |
This changeset introduces 29 new violations, 0 new errors and 0 new configuration errors,
removes 2 violations, 0 errors and 0 configuration errors.
Full report |
| ✅ |
This changeset introduces 29 new violations, 0 new errors and 0 new configuration errors,
removes 405 violations, 0 errors and 0 configuration errors.
Full report |
| ✅ |
This changeset introduces 390 new violations, 0 new errors and 0 new configuration errors,
removes 390 violations, 2 errors and 2 configuration errors.
Full report |
Generated by 🚫 Danger
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
the report switched all Spring violations to say JUnit 5, but AFAIK all imports are for JUnit 4 annotations… I need to look deeper to understand what's going on
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
adangel
commented
May 18, 2020
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
the report switched all Spring violations to say JUnit 5, but AFAIK all imports are for JUnit 4 annotations… I need to look deeper to understand what's going on
good catch. We probably should assert the messages in the test cases, so that we really report Junit4 for junit4 and junit5 for junit5 cases....
If this is reproducible in the unit tests, then we don't need to investigate further....
Also note, that the regression tester doesn't use typeresolution, so that might be one difference....
Edit: I see, we already assert the messages... so it seems to be a typeresolution thing. In PMD's code base we have both junit4 and 5 on the classpath, so typeresolution simply works. In the regression tester, we have none, so we might fallback with simple class name "Test", which matches both Junit4 and 5, but Junit5 is tested earlier and wins?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
If there is no auxclasspath, then we still can use imports to
check the full name before we fallback to simple name only.
Also improve RuleTst to actually test without auxclasspath
adangel
added a commit
that referenced
this pull request
May 22, 2020
[java] MethodNamingConventions - Add support for JUnit 5 method naming #2476
Reviewers
adangel
adangel approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|