UTBotJava
UTBotJava copied to clipboard
UTBot may generate wrong expected value when class contains mutation method
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
- Install UnitTestBot plugin built from main in IntelliJ IDEA
- Open UTBotJava project
- Set Test generation method -> Fuzzer = 100% (that's just to better illustrate the problem, similar issue with symbolic engine)
- Generate tests for whole
ClassWithEnumclass - Run
testUseGettergenerated 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.