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

Support mock strategies and type replacement in Spring unit test fuzzing #2561

Merged
merged 10 commits into from
Sep 19, 2023

Conversation

IlyaMuravjov
Copy link
Collaborator

@IlyaMuravjov IlyaMuravjov commented Aug 28, 2023

Description

Makes fuzzing in Spring unit tests respect mock strategy and type replacement:

  • All types are replaced according to selected Spring configuration before they are passed to actual value providers.
  • MockValueProvider is used if mock strategy allows it and type isn't replaced, otherwise ObjectValueProvider is used (MockValueProvider is also used when no other way to create non-null value is found)
  • InjectMockValueProvider (one that outputs composite models) is only used to create thisInstance.

How to test

Manual tests

Generate unit tests with every mocking strategy (including Spring-specific mocking strategy that uses Spring configuration) for spring-boot-testing project.

Self-check list

  • I've set the proper labels for my PR (at least, for category and component).
  • PR title and description are clear and intelligible.
  • I've added enough comments to my code, particularly in hard-to-understand areas.
  • The functionality I've repaired, changed or added is covered with automated tests.
  • Manual tests have been provided optionally.
  • The documentation for the functionality I've been working on is up-to-date.

@IlyaMuravjov IlyaMuravjov added ctg-enhancement New feature, improvement or change request comp-fuzzing Issue is related to the fuzzing comp-spring Issue is related to Spring projects support labels Aug 28, 2023
@IlyaMuravjov IlyaMuravjov force-pushed the ilya_m/unit_test_fuzz_modes branch 2 times, most recently from 701fb39 to 163e168 Compare August 29, 2023 12:48
@IlyaMuravjov IlyaMuravjov marked this pull request as ready for review August 29, 2023 13:36
@IlyaMuravjov IlyaMuravjov requested review from Vassiliy-Kudryashov and Damtev and removed request for Vassiliy-Kudryashov September 5, 2023 20:22
@Damtev
Copy link
Member

Damtev commented Sep 11, 2023

@Markoutte, could you take a look, please?

Copy link
Collaborator

@Markoutte Markoutte left a comment

Choose a reason for hiding this comment

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

For me it is hard to understand all type hierarchy in Spring module and all those wrappers, delegators and adapters. Maybe, documentation could help?

* arbitrary types, unlike type-specific value providers that were designed to provide values of
* few specific popular types (e.g. `List`, `String`, etc.).
*/
interface AnyObjectValueProvider : JavaValueProvider
Copy link
Collaborator

Choose a reason for hiding this comment

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

Marker interface usually doesn't extend any other interfaces and has no methods. This is because you could use several marker interfaces for one class. In this case AnyObjectValueProvider is used as real type in hierarchy, that maybe useful, but I think it is redundant.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not redundant, because it's used in MockingJavaFuzzingContext, which avoids mocking types that have value providers other than AnyObjectValueProvider, because it's a bad practice to mock types like List, Date, and Map.

I can't simply list all implementers of AnyObjectValueProvider in MockingJavaFuzzingContext, because the set of these implementers is subject to change as #2583 shows.

Made AnyObjectValueProvider truly a marker interface that doesn't extend any interfaces.

@alisevych alisevych added this to the September Release milestone Sep 19, 2023
@EgorkaKulikov EgorkaKulikov merged commit 36c23ff into main Sep 19, 2023
36 checks passed
@EgorkaKulikov EgorkaKulikov deleted the ilya_m/unit_test_fuzz_modes branch September 19, 2023 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-fuzzing Issue is related to the fuzzing comp-spring Issue is related to Spring projects support ctg-enhancement New feature, improvement or change request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants