Skip to content

The wrapper for String.split() uses concrete execution #41

@dtim

Description

@dtim

Description

String class has two overloaded methods to split the string around matches of the given regular expressions:

  • String[] split(String regex)
  • String[] split(String regex, int limit)

These methods are implemented in UtString via concrete execution. It prevents the symbolic engine to trace possible paths in these methods.

To Reproduce

Create a method with a call to String.split and generate a test suite for this method:

public class SplitExample {
    public boolean hasManyWords(@NotNull String str) {
        String[] components = str.split(" ");
        return components.length >= 3;
    }
}

Expected behavior

A test suite with two tests, one for each possible return value of hasManyWords (true and false).

Actual behavior

A test suite with only one test corresponding to false as the return value.

Visual proofs

///region SUCCESSFUL EXECUTIONS for method hasManyWords(java.lang.String)

/**
 *
 */
@Test
@DisplayName("hasManyWords: ")
public void testHasManyWords() throws Throwable {
    MissingMethods missingMethods = new MissingMethods();
    String string = "";

    boolean actual = missingMethods.hasManyWords(string);

    assertFalse(actual);
}
///endregion

Environment

Test framework: JUnit5 (the issue does not depend on the test framework).

Java: 8 (Corretto 1.8.0_332)

Mockito: any settings produce the same behavior.

Test: not parameterized

Metadata

Metadata

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