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

Investigate how to use fuzzing in Spring unit tests #2321

Closed
EgorkaKulikov opened this issue Jun 28, 2023 · 2 comments · Fixed by #2529
Closed

Investigate how to use fuzzing in Spring unit tests #2321

EgorkaKulikov opened this issue Jun 28, 2023 · 2 comments · Fixed by #2529
Assignees
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

Comments

@EgorkaKulikov
Copy link
Collaborator

EgorkaKulikov commented Jun 28, 2023

Description

We should finally investigate what to do with fuzzer in unit tests.

  1. First of all, how can it be used in No configuration mode?
  • May be for non-Spring classes (that do not inject mocks)
  • May be for the items, that cannot be injected from Spring (e.g. collections passed to constructors)?
  1. Investigate is it useful to generate unit tests with Fuzzing with Spring configuration applied
    Substitute interfaces with implementations.
    Seems that at least non-Spring classes (that do not inject mocks) Fuzzer may be useful in the mode with configuration too.
    Investigate other cases to use Fuzzing with configuration.

  2. There is a connected question how do we test some Utils class in Spring projects now, that injects nothing

  • with engine?
  • with fuzzer?
@EgorkaKulikov EgorkaKulikov 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 Jun 28, 2023
@IlyaMuravjov
Copy link
Collaborator

One not mentioned alternative, is to always use fuzzing in unit tests, and generate two (possibly nested) test classes:

  • test class with @InjectMock and engine generated tests;
  • test class without @InjectMock and fuzzer generated tests.

Furthermore, if either of these classes turns out to be empty we should skip it.

Finally, the only scenario when these two test classes can be merged into one seem to be when we have no @Mock fields.

@alisevych alisevych changed the title Properly use fuzzing in Spring unit tests Investigate how to use fuzzing in Spring unit tests Jul 17, 2023
@alisevych
Copy link
Member

@IlyaMuravjov Please discuss possibility of mocking in Spring-specific-only Fuzzing

@alisevych alisevych assigned IlyaMuravjov and unassigned sofurihafe Jul 31, 2023
IlyaMuravjov added a commit that referenced this issue Aug 21, 2023
* Extract `JavaFuzzingContext` into separate interface

* Add mock and inject mocks value providers

* Add `StateBeforeAwareIdGenerator`

* Properly handle `canHaveRedundantOrMissingMocks` in instrumentation

* Properly create `void` models (for mocking `void` methods)

* Add utils to ease configuring `ApplicationContext`

* Configure Spring unit tests to use fuzzer with mocks

* Refactor to only transform `JavaValueProvider` via `applicationContext` (avoid redundant lambdas)

* Fix test compilation

* Improve default mock answers of unmockable types (arrays and sealed interfaces)

* Set default fuzzing value to 0.3 for Spring

* Avoid creating too deep dynamic mocks

* Avoid recording multiple mock answers if same answer is reused over and over again

* Fix JS compilation

---------

Co-authored-by: Egor Kulikov <[email protected]>
@github-project-automation github-project-automation bot moved this from Todo to Done in UTBot Java Aug 21, 2023
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
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants