UTBotJava icon indicating copy to clipboard operation
UTBotJava copied to clipboard

UTBot may generate wrong expected value when class contains mutation method

Open tyuldashev opened this issue 3 years ago • 0 comments

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 avatar Oct 02 '23 10:10 tyuldashev