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

UTBot may generate wrong expected value when class contains mutation method #2634

Open
tyuldashev opened this issue Oct 2, 2023 · 0 comments
Assignees
Labels
comp-instrumented-process Issue is related to Instrumented process ctg-bug Issue is a bug

Comments

@tyuldashev
Copy link
Collaborator

Description
When class contains methods which update (mutate) class fields then UtBot sometimes may use that update value as expected value for another tested method instead of using original field value.

To Reproduce

  1. Install UnitTestBot plugin built from main in IntelliJ IDEA
  2. Open UTBotJava project
  3. Set Test generation method -> Fuzzer = 100% (that's just to better illustrate the problem, similar issue with symbolic engine)
  4. Generate tests for whole ClassWithEnum class
  5. Run testUseGetter generated test

Expected behavior
Test passes

Actual behavior
Test fails

Screenshots, logs

Code of testUseGetter test. Return value from useGetter(null) is -1, so it fails.

    @Test
    @DisplayName("useGetter: s = null -> return -2")
    public void testUseGetter() {
        ClassWithEnum classWithEnum = new ClassWithEnum();

        int actual = classWithEnum.useGetter(null);

        assertEquals(-2, actual);
    

Additional context
If test is generated only for useGetter method then everything is okay and test passes. That's because when UTBot generates tests for whole class it also invokes changeMutableField(StatusEnum statusEnum) methods with updates StatusEnum.READY.mutableInt value to '-2', which later used as expected value.

@tyuldashev tyuldashev added ctg-bug Issue is a bug comp-instrumented-process Issue is related to Instrumented process labels Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-instrumented-process Issue is related to Instrumented process ctg-bug Issue is a bug
Projects
Status: Todo
Development

No branches or pull requests

2 participants