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

Reduced mockito usage #2767

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Reduced mockito usage #2767

wants to merge 1 commit into from

Conversation

jkronegg
Copy link
Contributor

@jkronegg jkronegg commented Jun 6, 2023

🤔 What's changed?

I reduced the usage of the Mockito framework. This is a first pass, focused on the simple cases (typically: replacing the mock+when constructs with stub classes).

⚡️ What's your motivation?

Fixes #2707 .

By focusing on the simple cases we have a big pull request of stuff that is simple to review. The other replacements are more complex and prone to more discussions, so I will make another pull request for them.

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, documentation etc. without changing behaviour)

♻️ Anything particular you want feedback on?

Performance when running all tests using Intellij (right click on project -> Run -> All Tests ; average duration over 5 runs):

project test duration (before -> after) [s] mockito contribution (before -> after)
cucumber-junit 3.3 -> 1.1 2.2 s = 68% -> 0% (removed dependency)
cucumber-core 9.3 -> 6.4 2.9 s = 31% -> 0% (removed dependency)
cucumber-java 2.7 -> 0.8 1.9 s = 72% -> 0% (removed dependency)
cucumber-java8 0.9 -> 0.7 0.2 s = 21% -> 0% (removed dependency)
cucumber-spring 5.3 -> 3.2 2.0 s = 39% -> 0% (removed dependency)
cucumber-testng 1.7 -> 1.7 0.0 s = 0% -> 0% (removed dependency)
cucumber-guice 2.4 -> 0.7 1.7 s = 71% -> 0% (removed dependency)
datatable 0.5 -> 0.5 (unused dependency) 0.0 s = 0% -> 0% (removed dependency)

Thus, when running tests interactively, we see a good improvement by not using mockito (up to 72% of testing time on cucumber-java).

However, over the full build (maven clean install on cucumber-jvm), there is no build time difference: on my machine, the build time is 1 minute 49 seconds on the main branch as well as on branch reduce-mockito-usage-pass1 (average build time over 5 builds).

My guess is that the build time is much longer than the test duration, so the test duration on total maven clean+install is not noticeable.

Edit:
One year after, I did additional tests on my local machine for a maven clean install on cucumber-jvm (5 times average):

  • with mockito ( main branch ): average=3 minutes 42 seconds (standard deviation = 8 seconds)
  • without mockito (reduce-mockito-usage-pass1 branch): average=3 minutes 26 seconds (standard deviation = 12 seconds)

That is: the build is 7% faster without mockito.

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

@jkronegg jkronegg requested a review from mpkorstanje June 6, 2023 05:16
@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.00%. Comparing base (ba6a53d) to head (f75916b).
Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2767      +/-   ##
============================================
+ Coverage     84.99%   85.00%   +0.01%     
- Complexity     2734     2736       +2     
============================================
  Files           331      331              
  Lines          9559     9559              
  Branches        918      918              
============================================
+ Hits           8125     8126       +1     
  Misses         1109     1109              
+ Partials        325      324       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

jkronegg pushed a commit that referenced this pull request Aug 4, 2023
jkronegg pushed a commit that referenced this pull request Aug 4, 2023
@jkronegg jkronegg marked this pull request as draft August 5, 2023 19:46
jkronegg pushed a commit that referenced this pull request Aug 5, 2023
@mpkorstanje
Copy link
Contributor

I'm halfway through reviewing this. Made #2783 to reduce the size a bit.

jkronegg pushed a commit that referenced this pull request Oct 22, 2023
@jkronegg jkronegg changed the title Reduced mockito usage (pass 1: simple cases) Reduced mockito usage Oct 22, 2023
@jkronegg jkronegg marked this pull request as ready for review October 22, 2023 20:28
@jkronegg
Copy link
Contributor Author

jkronegg commented Oct 22, 2023

I removed all mockito usages. I'm happy with the performance improvement on interactive tests, but a bit puzzled by having the same build duration with or without mockito when doing a maven clean+install.
Edit:
The build is not 7% faster without mockito, see top post for details.

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.

Reduce build duration by lowering Mockito usage
2 participants