Skip to content

Public constructors are not used when available #2633

@alisevych

Description

@alisevych

Description

Generated tests for ClassWithComplicatedMethods use UtUtils method createInstance,
while there are public constructors.

To Reproduce

  1. Install UnitTestBot -IU- plugin built from main in IntelliJ IDEA
  2. Open utbot-sample module in UTBotJava project
  3. Generate tests for ClassWithComplicatedMethods
  4. Find createInstance calls in generated tests

Expected behavior

ClassWithComplicatedMethods has public constructors with a and b parameters.
Is it expected that they are used? Only a is used in path constraints.

Actual behavior

createInstance is called in all tests generated with Symbolic execution

Screenshots, logs

    ///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method applyMethodWithSideEffectAndReturn(int)

    /**
     * @utbot.classUnderTest {@link ClassWithComplicatedMethods}
     * @utbot.methodUnderTest {@link ClassWithComplicatedMethods#applyMethodWithSideEffectAndReturn(int)}
     * @utbot.executesCondition {@code (a == 2821): False}
     * @utbot.invokes org.utbot.examples.make.symbolic.ClassWithComplicatedMethods#methodWithSideEffect(int)
     */
    @Test
    @DisplayName("applyMethodWithSideEffectAndReturn: ClassWithComplicatedMethodsMethodWithSideEffect -> return this")
    public void testApplyMethodWithSideEffectAndReturn_ANotEquals2821() throws Exception {
        ClassWithComplicatedMethods classWithComplicatedMethods = ((ClassWithComplicatedMethods) createInstance("org.utbot.examples.make.symbolic.ClassWithComplicatedMethods"));
        classWithComplicatedMethods.a = 15;

        ClassWithComplicatedMethods actual = classWithComplicatedMethods.applyMethodWithSideEffectAndReturn(1);

        int classWithComplicatedMethodsA = classWithComplicatedMethods.a;
        int actualA = actual.a;
        assertEquals(classWithComplicatedMethodsA, actualA);

        int finalClassWithComplicatedMethodsA = classWithComplicatedMethods.a;

        assertEquals(2821, finalClassWithComplicatedMethodsA);
    }
    ///endregion

Environment

IntelliJ IDEA version - Ultimate 2023.2
Project - Gradle
JDK - 17

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bugstatus-wont-fixThis will not be worked on

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions