Skip to content

No true branch test is generated for code with String.split(";\\s") #885

Closed
@alisevych

Description

@alisevych

Description

No test is generated for the true branch of the condition with String.split(";\s")

To Reproduce

Steps to reproduce the behavior:

  1. IntelliJ IDEA with UTBot plugin installed
  2. Fuzzing is on, slider is in default position
  3. Add the following Java class:
public class StringCharAt {
    public boolean isSplitted(String s) {
        if (s.split(";\\s").length > 1) {
            return true;
        }
        return false;
    }
}
  1. Use plugin to generate tests
  2. Open the generated test

Expected behavior

Tests are supposed to be generated for all code branches.

Actual behavior

There is only one successful test - with empty String, which is for the false branch.

Visual proofs (screenshots, logs, images)

The following test class is generated:

public class StringCharAtTest {
    ///region Test suites for executable StringCharAt.isSplitted

    ///region FUZZER: SUCCESSFUL EXECUTIONS for method isSplitted(java.lang.String)

    @Test
    @DisplayName("isSplitted: s = empty string -> return false")
    public void testIsSplittedReturnsFalseWithEmptyString() {
        StringCharAt stringCharAt = new StringCharAt();

        boolean actual = stringCharAt.isSplitted("");

        assertFalse(actual);
    }
    ///endregion

    ///region SYMBOLIC EXECUTION ENGINE: ERROR SUITE for method isSplitted(java.lang.String)

    /**
     * <pre>
     * Test invokes:
     *     {@link String#split(String)} once
     *
     * throws NullPointerException in: s.split("<\\s").length > 1
     * </pre>
     */
    @Test
    @DisplayName("isSplitted: s.split(\"<\\\\s\").length > 1 -> ThrowNullPointerException")
    public void testIsSplitted_StringSplit() {
        StringCharAt stringCharAt = new StringCharAt();
        
        /* This test fails because method [StringCharAt.isSplitted] produces [java.lang.NullPointerException]
            StringCharAt.isSplitted(StringCharAt.java:11) */
        stringCharAt.isSplitted(null);
    }
    ///endregion

    ///endregion
}

Environment

Windows 10 Pro
JDK 11

Additional context

The same number of tests is generated for the following regex used : "<\s", ";\s"
If only "\s" or ";" is used - all branches are covered.

Metadata

Metadata

Assignees

Labels

ctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions