GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@birdflyer-lszo birdflyer-lszo commented May 11, 2020 •
edited by adangel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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.

All reactions
Ritz, Bruno added 2 commits May 11, 2020 11:43
Ritz, Bruno Ritz, Bruno
Add support for JUnit 5 method naming
db590fd
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.
Ritz, Bruno Ritz, Bruno
Add a test case for the JUnit 5 naming rules
a0e2558
@birdflyer-lszo birdflyer-lszo changed the title Feature/junit5 method naming [java] MethodNamingConventions - Add support for JUnit 5 method naming May 11, 2020
@ghost

ghost commented May 11, 2020 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added this to the 6.24.0 milestone May 14, 2020
adangel
adangel approved these changes May 14, 2020
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

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.

Thanks! Looks good!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jsotuyod

jsotuyod commented May 14, 2020

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel

adangel commented May 18, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel self-assigned this May 22, 2020
adangel added 2 commits May 22, 2020 17:06
@adangel
[java] Fix typehelper fallback for simple class name
5a6cb7b
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
[java] Fix TypeHelper if the searched type is not fully qualified
aa1722e
adangel added a commit that referenced this pull request May 22, 2020
@adangel
[doc] Update release notes, refs #2476
d0eb329
adangel added a commit that referenced this pull request May 22, 2020
@adangel
Merge branch 'pr-2476'
bf16b50
[java] MethodNamingConventions - Add support for JUnit 5 method naming #2476
@adangel
adangel merged commit aa1722e into pmd:master May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

None yet

Projects

None yet

Milestone

6.24.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@birdflyer-lszo @jsotuyod @adangel
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.