Skip to content

Incorrect parameterized tests are generated for Sort.partition #1388

Description

@alisevych

Description

Incorrect parameterized tests are generated for Sort.partition
There are test executions that fail with unexpected NPE and ones that are expecting ArrayIndexOutOfBoundsException but failed to get it.

To Reproduce

  1. Install one of the latest plugin builds from main in IDEA
  2. Run the 'UTBotJava' project in IntelliJ Idea
  3. Set defaults in Settings->Tools->UnitTestBot
  4. Use plugin to generate Parameterized tests, No mocks for sample: org.utbot.examples.algorithms.Sort.partition()
  5. Run the generated parameterized tests

Expected behavior

Tests are supposed to pass.
Expected result and actual should match.
AssertionErrors should be thrown upwards without changes.

Actual behavior

There are NPE from assertion.
There is expected result 0, while actual is -1 . Assert failed and AssertionError is also caught outside and misunderstood.

Case#arraybeginendexpected resultactual resultexpected erroractual error
1{-255L, -255L}10(!) 0null(!) nullIllegalArgument: bound must be positive
3{2, -192, -255, -255, -255, -255, -255, -255, 1, -255, -255, -255}00(!) 0-1null(!) AssertionFailedError: expected: <0> but was: <-1>
5{-255}-192-255nullnull(!) ArrayIndexOutOfBoundsIllegalArgumentException: bound must be positive
7{1, 0}00(!) null-1(!) ArrayIndexOutOfBounds(!) AssertionFailedError: expected: but was: <-1>
8{-254, -255}11(!) null0(!) ArrayIndexOutOfBounds(!) AssertionFailedError: expected: but was: <0>

Visual proofs (screenshots, logs, images)

publicfinalclassSortTest {
///region Test suites for executable org.utbot.examples.algorithms.Sort.partition///region Parameterized test for method partition(long[], int, int)@ParameterizedTest@MethodSource("org.utbot.examples.algorithms.SortTest#provideDataForPartition")
publicvoidparameterizedTestsForPartition(Sortsort,
long[] array,
intbegin,
intend,
IntegerexpectedResult,
ClassexpectedError
) {
try {
intactual = sort.partition(array, begin, end);
assertEquals(expectedResult, actual);
} catch (Throwablethrowable) {
assertTrue(expectedError.isInstance(throwable));
}
}
///endregion///endregion///region Data provider methods for parametrized testspublicstaticArrayListprovideDataForPartition() {
ArrayListargList = newArrayList();
{
Sortsort = newSort();
long[] array = {-255L, -255L};
Object[] testCaseObjects = newObject[6];
testCaseObjects[0] = sort;
testCaseObjects[1] = array;
testCaseObjects[2] = 1;
testCaseObjects[3] = 0;
testCaseObjects[4] = 0;
testCaseObjects[5] = null;
argList.add(arguments(testCaseObjects));
}
{
Sortsort = newSort();
long[] array = {12L};
Object[] testCaseObjects = newObject[6];
testCaseObjects[0] = sort;
testCaseObjects[1] = array;
testCaseObjects[2] = 0;
testCaseObjects[3] = 0;
testCaseObjects[4] = -1;
testCaseObjects[5] = null;
argList.add(arguments(testCaseObjects));
}
{
Sortsort = newSort();
long[] array = newlong[13];
array[1] = 2L;
array[2] = -192L;
array[3] = -255L;
array[4] = -255L;
array[5] = -255L;
array[6] = -255L;
array[7] = -255L;
array[8] = -255L;
array[9] = 1L;
array[10] = -255L;
array[11] = -255L;
array[12] = -255L;
Object[] testCaseObjects = newObject[6];
testCaseObjects[0] = sort;
testCaseObjects[1] = array;
testCaseObjects[2] = 0;
testCaseObjects[3] = 0;
testCaseObjects[4] = 0;
testCaseObjects[5] = null;
argList.add(arguments(testCaseObjects));
}
{
Sortsort = newSort();
Object[] testCaseObjects = newObject[6];
testCaseObjects[0] = sort;
testCaseObjects[1] = null;
testCaseObjects[2] = -255;
testCaseObjects[3] = -255;
testCaseObjects[4] = null;
testCaseObjects[5] = NullPointerException.class;
argList.add(arguments(testCaseObjects));
}
{
Sortsort = newSort();
long[] array = {-255L};
Object[] testCaseObjects = newObject[6];
testCaseObjects[0] = sort;
testCaseObjects[1] = array;
testCaseObjects[2] = -192;
testCaseObjects[3] = -255;
testCaseObjects[4] = null;
testCaseObjects[5] = ArrayIndexOutOfBoundsException.class;
argList.add(arguments(testCaseObjects));
}
{
Sortsort = newSort();
long[] array = {-255L};
Object[] testCaseObjects = newObject[6];
testCaseObjects[0] = sort;
testCaseObjects[1] = array;
testCaseObjects[2] = -254;
testCaseObjects[3] = -254;
testCaseObjects[4] = null;
testCaseObjects[5] = ArrayIndexOutOfBoundsException.class;
argList.add(arguments(testCaseObjects));
}
{
Sortsort = newSort();
long[] array = {1L, 0L};
Object[] testCaseObjects = newObject[6];
testCaseObjects[0] = sort;
testCaseObjects[1] = array;
testCaseObjects[2] = 0;
testCaseObjects[3] = 0;
testCaseObjects[4] = null;
testCaseObjects[5] = ArrayIndexOutOfBoundsException.class;
argList.add(arguments(testCaseObjects));
}
{
Sortsort = newSort();
long[] array = {-254L, -255L};
Object[] testCaseObjects = newObject[6];
testCaseObjects[0] = sort;
testCaseObjects[1] = array;
testCaseObjects[2] = 1;
testCaseObjects[3] = 1;
testCaseObjects[4] = null;
testCaseObjects[5] = ArrayIndexOutOfBoundsException.class;
argList.add(arguments(testCaseObjects));
}
returnargList;
}
///endregion
}

Environment

IntelliJ IDEA 2022.2.3
Gradle
JDK 11
JUnit 5 + parameterized

Additional context

Tests generated by Fuzzing are correct.

Metadata

Metadata

Assignees

Labels

ctg-bugIssue is a bug

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions