Closed
Description
Description
When Enum class is created by className, it addresses not class but the Enum constant.
To Reproduce
- Run the 'UTBotJava' project in IntelliJ Idea
- Install plugin build or one of the latest builds from main. Reproducing on more early build too
- Generate tests for utbot-sample/src/main/java/org/utbot/examples/enums
with No mocks, No parameterization. - Run the generated tests
Expected behavior
Assertions in generated tests are supposed to pass.
Actual behavior
There are assertion errors in tests - for every class in the package.
Please see the Class creation: State$3
is addressing not the State enum, but the third constant in it.
Visual proofs (screenshots, logs, images)
///region Test suites for executable org.utbot.examples.enums.ComplexEnumExamples.findState
///region FUZZER: SUCCESSFUL EXECUTIONS for method findState(int)
@Test
@DisplayName("findState: code > 0")
public void testFindState() throws ClassNotFoundException, IllegalAccessException {
ComplexEnumExamples complexEnumExamples = new ComplexEnumExamples();
State actual = complexEnumExamples.findState(1);
Class anonymousStateClazz = Class.forName("org.utbot.examples.enums.State$3");
Object expected = getEnumConstantByName(anonymousStateClazz, "UNKNOWN");
assertEquals(expected, actual);
}
same for Symbolic execution:
///region Test suites for executable org.utbot.examples.enums.State.findStateByCode
///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method findStateByCode(int)
/**
* @utbot.classUnderTest {@link State}
* @utbot.methodUnderTest {@link State#findStateByCode(int)}
*/
@Test
@DisplayName("findStateByCode: ")
public void testFindStateByCode() throws ClassNotFoundException, IllegalAccessException {
State actual = State.findStateByCode(255);
Class anonymousStateClazz = Class.forName("org.utbot.examples.enums.State$1");
Object expected = getEnumConstantByName(anonymousStateClazz, "OPEN");
assertEquals(expected, actual);
}
Additional context
Same issue with Fuzzing and / or Symbolic execution.
These tests are also failing when running in debug IDEA with runIde.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done