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

[Mutation Testing] Pitest Gradle Plugin #12208

Draft
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

ParaskP7
Copy link
Contributor

@ParaskP7 ParaskP7 commented Aug 2, 2024

Description

TODO

Testing information

TODO

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

Release Notes (Mockito): https://github.com/mockito/
mockito/releases/tag/v5.12.0
Release Notes (Mockito Kotlin): https://github.com/mockito/
mockito-kotlin/releases/tag/5.4.0

------------------------------------------------------------------------

Note that the 'org.mockito:mockito-inline' dependency is now switched
with 'org.mockito:mockito-core' and this is because the inline bytecode
functionality that 'mockito-inline' provided is now the default and part
of 'mockito-core'. Mockito version '5.0.0' introduced this change.

------------------------------------------------------------------------

FYI: This is done in order to make sure that Pitest is working with the
most recent version of Mockito when running tests. This is because,
sometimes, even though normally tests run green, Pitest says that the
suite isn't green. And this happens because Pitest, to make things fast,
does some tricky stuff to split your tests into small independent units.

For more info see: https://pitest.org/faq/
This change is required as part of the Mockito update, which is causing
the test to compile with the below error message:

Error Message: "Cannot inline bytecode built with JVM target 11 into
bytecode that is being built with JVM target 1.8. Please specify proper
'-jvm-target' option"
This is done because otherwise the Pitest is failing when running some
tests with the below example failure message:

Example Failure Message: "java.lang.RuntimeException: Method i in
android.util.Log not mocked. See https://developer.android.com/r/
studio-ui/build/not-mocked for details."

For more info see: https://developer.android.com/training/testing/
local-tests#mocking-dependencies
For the Pitest plugin to work with Gradle, the project needs to use the
'gradle-pitest-plugin'. However, this Pitest Gradle plugin is not
working with Android project. As such, a fork of that was created by
Karlo, an Android developer working with 'Droids On Roids', a mobile app
development company.

Main Gradle Plugin: https://github.com/szpak/gradle-pitest-plugin
Fork Gradle Plugin: https://github.com/koral--/gradle-pitest-plugin

------------------------------------------------------------------------

PS: Arcmutate and its accompanying Kotlin plugin can further enhance the
mutation testing experience on Kotlin projects, but this requires a
licence first. The good news is that using this license is free for
open source projects.

Arcmutate Kotlin Support: https://docs.arcmutate.com/docs/
kotlin.html#installation
This is done because otherwise mutation testing will fail with the below
build failure message:

Build Failure Message: "(9) tests did not pass without mutation when
calculating line coverage"

From those 9 tests, 5 are related to the
'OrderDetailsTransactionLauncherTest' test suite, while the rest 4 are
related to the 'OrderListTransactionLauncherTest' test suite.

The problem is that Mockiot cannot mock these classes, as it cannot mock
final classes with the following settings:
- explicit serialization (e.g. withSettings().serializable())
- extra interfaces (e.g. withSettings().extraInterfaces(...))

------------------------------------------------------------------------

For more info see the full(ish) stacktrace below:

Mockito cannot mock this class: class com.automattic.android.tracks.
crashlogging.performance.PerformanceTransactionRepository.
Can not mock final classes with the following settings :
- explicit serialization (e.g. withSettings().serializable())
- extra interfaces (e.g. withSettings().extraInterfaces(...))
...
Caused by: org.mockito.exceptions.base.MockitoException:
Could not modify all classes [class com.automattic.android.tracks.
crashlogging.performance.PerformanceTransactionRepository]
...
Caused by: java.lang.IllegalStateException: Byte Buddy could not
instrument all classes within the mock's type hierarchy
...
This problem should never occur for javac-compiled classes. This problem
has been observed for classes that are:
- Compiled by older versions of scalac
- Classes that are part of the Android distribution
...
Caused by: java.lang.TypeNotPresentException: Type io.sentry
.ITransaction not present
...
Caused by: java.lang.ClassNotFoundException: io.sentry.ITransaction
@ParaskP7 ParaskP7 added status: do not merge Dependent on another PR, ready for review but not ready for merge. category: tooling Anything that involves building & maintaining the project, including scripts, `Fastfile`, etc. Testing Core labels Aug 2, 2024
@dangermattic
Copy link
Collaborator

1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commit40fc7c4
Direct Downloadwoocommerce-wear-prototype-build-pr12208-40fc7c4.apk

@wpmobilebot
Copy link
Collaborator

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commit40fc7c4
Direct Downloadwoocommerce-prototype-build-pr12208-40fc7c4.apk

@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.84%. Comparing base (acbccb7) to head (40fc7c4).
Report is 15 commits behind head on trunk.

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #12208      +/-   ##
============================================
- Coverage     39.97%   39.84%   -0.13%     
+ Complexity     5579     5555      -24     
============================================
  Files          1214     1214              
  Lines         69276    69274       -2     
  Branches       9702     9702              
============================================
- Hits          27690    27604      -86     
- Misses        39004    39093      +89     
+ Partials       2582     2577       -5     

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: tooling Anything that involves building & maintaining the project, including scripts, `Fastfile`, etc. Core status: do not merge Dependent on another PR, ready for review but not ready for merge. Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants