Skip to content

No test is generated for String.equals() in condition #2149

Open
@pogrebnoijak

Description

@pogrebnoijak

Description

No test is generated for String.equals() in condition by Symbolic engine.

To Reproduce

Generate tests for the following code using Symbolic-100% mode:

    public boolean example(String[] l) {
        if (l[0].equals("example")) {
            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/ArrayCheck.java --output Test.java org.example.checks.ArrayCheck

Expected behavior

Expected tests for true, false and exceptions.

Actual behavior

Test is generated only for false branch and exceptions.

Visual proofs (screenshots, logs, images)

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.ArrayCheck.example
    
    ///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method example(java.lang.String[])
    
    /**
    @utbot.classUnderTest {@link ArrayCheck}
 * @utbot.methodUnderTest {@link org.example.checks.ArrayCheck#example(java.lang.String[])}
 * @utbot.executesCondition {@code (l[0].equals("example")): True}
 * @utbot.invokes {@link java.lang.String#equals(java.lang.Object)}
 * @utbot.returnsFrom {@code return true;}
 *  */
    @Test
    public void testExample_L0Equals() {
        ArrayCheck arrayCheck = new ArrayCheck();
        java.lang.String[] stringArray = new java.lang.String[1];
        String string = "";
        stringArray[0] = string;
        
        boolean actual = arrayCheck.example(stringArray);
        
        assertFalse(actual);
    }
    ///endregion
    
    ///region SYMBOLIC EXECUTION: ERROR SUITE for method example(java.lang.String[])
    
    /**
    @utbot.classUnderTest {@link ArrayCheck}
 * @utbot.methodUnderTest {@link org.example.checks.ArrayCheck#example(java.lang.String[])}
 * @utbot.throwsException {@link java.lang.NullPointerException} in: l[0].equals("example")
 *  */
    @Test
    public void testExample_ThrowNullPointerException() {
        ArrayCheck arrayCheck = new ArrayCheck();
        
        /* This test fails because method [org.example.checks.ArrayCheck.example] produces [java.lang.NullPointerException]
            org.example.checks.ArrayCheck.example(ArrayCheck.java:5) */
        arrayCheck.example(null);
    }
    
    /**
    @utbot.classUnderTest {@link ArrayCheck}
 * @utbot.methodUnderTest {@link org.example.checks.ArrayCheck#example(java.lang.String[])}
 * @utbot.throwsException {@link java.lang.ArrayIndexOutOfBoundsException} in: l[0].equals("example")
 *  */
    @Test
    public void testExample_ThrowArrayIndexOutOfBoundsException() {
        ArrayCheck arrayCheck = new ArrayCheck();
        java.lang.String[] stringArray = {};
        
        /* This test fails because method [org.example.checks.ArrayCheck.example] produces [java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0]
            org.example.checks.ArrayCheck.example(ArrayCheck.java:5) */
        arrayCheck.example(stringArray);
    }
    
    /**
    @utbot.classUnderTest {@link ArrayCheck}
 * @utbot.methodUnderTest {@link org.example.checks.ArrayCheck#example(java.lang.String[])}
 * @utbot.invokes {@link java.lang.String#equals(java.lang.Object)}
 * @utbot.throwsException {@link java.lang.NullPointerException} in: l[0].equals("example")
 *  */
    @Test
    public void testExample_StringEquals() {
        ArrayCheck arrayCheck = new ArrayCheck();
        java.lang.String[] stringArray = {null};
        
        /* This test fails because method [org.example.checks.ArrayCheck.example] produces [java.lang.NullPointerException]
            org.example.checks.ArrayCheck.example(ArrayCheck.java:5) */
        arrayCheck.example(stringArray);
    }
    ///endregion
    
    ///endregion
}

Environment

Ubuntu 21.04, jdk 17.

Additional context

For single String as the function parameter there are two branches covered: true and false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-symbolic-engineIssue is related to the symbolic execution enginectg-bugIssue is a bug

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions