Skip to content

Conversation

Napalys
Copy link
Contributor

@Napalys Napalys commented Aug 11, 2025

Ported the java/mocking-all-non-private-methods-means-unit-test-is-too-big query. Key changes:

  • Classes with only 1 public method being mocked are no longer flagged as true positives.
  • MRVA 1000 reduced from 1,332 to 250 results.
  • Autofix: Primarily focuses on trimming test cases to test a single method, which may or may not be considered as a acceptable fix as it may now not cover trimmed methods.

@Napalys Napalys added the no-change-note-required This PR does not need a change note label Aug 11, 2025
@Napalys Napalys force-pushed the java/mocking-all-non-private-methods-means-unit-test-is-too-big branch from f4a5e1e to cdb0d25 Compare August 11, 2025 11:43
@Napalys Napalys force-pushed the java/mocking-all-non-private-methods-means-unit-test-is-too-big branch from cdb0d25 to ff648fc Compare August 11, 2025 11:43
@Napalys Napalys marked this pull request as ready for review August 11, 2025 12:31
@Napalys Napalys requested a review from a team as a code owner August 11, 2025 12:31
@Copilot Copilot AI review requested due to automatic review settings August 11, 2025 12:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Ports the java/mocking-all-non-private-methods-means-unit-test-is-too-big query to detect unit tests that mock all public methods of a class, which may indicate the test is testing too much functionality.

Key changes:

  • Added logic to exclude classes with only 1 public method from being flagged as violations
  • Reduced false positive results from 1,332 to 250 on MRVA 1000
  • Added comprehensive test stubs for Mockito 5.14 and JUnit 4.13 to support the query functionality

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
java/ql/src/Likely Bugs/Frameworks/JUnit/MockingAllNonPrivateMethodsMeansUnitTestIsTooBig.ql Main query implementation that detects excessive mocking patterns
java/ql/src/Likely Bugs/Frameworks/JUnit/MockingAllNonPrivateMethodsMeansUnitTestIsTooBig.md Documentation explaining the rule and providing usage examples
java/ql/test/query-tests/MockingAllNonPrivateMethodsMeansUnitTestIsTooBig/ Test cases with expected results demonstrating compliant and non-compliant patterns
java/ql/test/stubs/mockito-5.14/ Mockito framework stubs for testing support
java/ql/test/stubs/junit-4.13/ JUnit 4.13 framework stubs for testing support
java/ql/integration-tests/java/query-suite/*.qls.expected Updated query suite expectations to include the new rule

@Napalys Napalys requested a review from knewbury01 August 11, 2025 13:04
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

Overall this looks good! Only a few questions / comments.

…test-is-too-big` to `java/excessive-public-method-mocking` and changed wording from non-private to public
@Napalys Napalys force-pushed the java/mocking-all-non-private-methods-means-unit-test-is-too-big branch from 467df42 to b271f1f Compare August 26, 2025 08:38
@Napalys Napalys requested a review from michaelnebel August 26, 2025 09:46
michaelnebel
michaelnebel previously approved these changes Aug 26, 2025
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@owen-mc owen-mc left a comment

Choose a reason for hiding this comment

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

I don't think "Likely Bugs" is the best folder for this query.

My only other concern is with the autofixes. Do you think they are good enough to add this to show the autofixes to users? Can you think of any way of improving them, e.g. with more complete examples in the qhelp?

@Napalys
Copy link
Contributor Author

Napalys commented Aug 28, 2025

@owen-mc

I don't think "Likely Bugs" is the best folder for this query.

Fair point, I agree. The main reason I moved it there was because of the Frameworks/JUnit. Do you have any suggestions for where it would fit better? Thank you ❤️

My only other concern is with the autofixes. Do you think they are good enough to add this to show the autofixes to users? Can you think of any way of improving them, e.g. with more complete examples in the qhelp?

I will try to think of something. 🤔

@owen-mc
Copy link
Contributor

owen-mc commented Aug 28, 2025

I think `Violations of Best Practice" is the best high-level folder. None of the existing subfolders really match, so maybe create a new one called "Testing".

It is an option to accept that autofixes aren't good for this query at the moment, and not add it to autofix.

…too-big` to a more appropriate location, namely `Violation of Best Practice/Testing`
@Napalys Napalys merged commit 73c8f3d into github:main Aug 28, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Java no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants