UnitTestBot / UTBotJava

Automated unit test generation and precise code analysis for Java
Apache License 2.0
136 stars 43 forks source link

No tests are generated for `true` branch with long string used in condition #2121

Closed pogrebnoijak closed 1 year ago

pogrebnoijak commented 1 year ago

Description

No tests are generated for true branch with long string used in condition (run without fuzzing)

To Reproduce

package org.example.checks;

public class StringCheck {
    public boolean example(String s) {
        String longPrefix = "...................."; // len = 20
        String result = longPrefix + s;
        if (result.equals("....................answer")) {  // len = 26
            return true;
        }
        return false;
    }
}

run utbot-cli in idea (fe0b89c):

program arguments: generate --classpath "/home/andrew/ex/build/classes/java/main" --source /home/andrew/ex/src/main/java/org/example/checks/StringCheck.java --output Test.java org.example.checks.StringCheck

Expected behavior

Generated tests for true and for false

Actual behavior

test only for false

package org.example.checks;

import org.junit.Test;

import static org.junit.Assert.assertFalse;

public final class Test {
    ///region Test suites for executable org.example.checks.StringCheck.example

    ///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method example(java.lang.String)

    /**
    @utbot.classUnderTest {@link StringCheck}
 * @utbot.methodUnderTest {@link org.example.checks.StringCheck#example(java.lang.String)}
 * @utbot.executesCondition {@code (result.equals("....................answer")): False}
 * @utbot.invokes {@link soot.dummy.InvokeDynamic#makeConcatWithConstants(java.lang.String,java.lang.String)}
 * @utbot.invokes {@link java.lang.String#equals(java.lang.Object)}
 * @utbot.returnsFrom {@code return false;}
 *  */
    @Test
    public void testExample_NotResultEquals() {
        StringCheck stringCheck = new StringCheck();

        boolean actual = stringCheck.example(null);

        assertFalse(actual);
    }
    ///endregion

    ///endregion
}

Environment

Ubuntu 21.04, jdk 17.

Other

If the string length in if $\leq 25$ everything works. How can I change this limit? (in any case, there is a limit to 40 - softMaxArraySize internally and it seems to be unrelated to this)

alisevych commented 1 year ago

It seems to be related to :

alisevych commented 1 year ago

@pogrebnoijak Such cases with String operations inside are not always covered with symbolic engine. Fuzzing can improve the coverage radically. But it's not 100% also.