Description
Generating test for streamOfExample method results in different outcomes when generating in runIde and as a sample.
RunIde version has empty else branch.
Also, it's important to notice that there are different actual and expectedResult types (Object vs. Stream).
To Reproduce
- Run
runIde, generate parametrized test for streamOfExample,
- Run
BaseStreamExampleTest as a sample (not in runIde),
- Compare generated tests.
Actual behavior
in runIde:

public class BaseStreamExampleTest {
///region Test suites for executable playground.BaseStreamExample.streamOfExample
///region Parameterized test for method streamOfExample(java.lang.Integer[])
@ParameterizedTest
@MethodSource("provideDataForStreamOfExample")
public void parameterizedTestsForStreamOfExample(BaseStreamExample baseStreamExample,
Integer[] values,
Object expectedResult,
Class expectedError
) {
try {
Object actual = baseStreamExample.streamOfExample(values);
if (expectedResult == null) {
assertNull(actual);
} else {
}
} catch (Throwable throwable) {
assertTrue(expectedError.isInstance(throwable));
}
}
///endregion
///endregion
///region Data providers and utils methods
public static ArrayList provideDataForStreamOfExample() throws Exception {
ArrayList argList = new ArrayList();
<...>
return argList;
}
<...>
}
as a sample:
public class BaseStreamExampleGeneratedTest {
///region Test suites for executable org.utbot.examples.stream.BaseStreamExample.streamOfExample
///region Parameterized test for method streamOfExample(java.lang.Integer[])
@ParameterizedTest
@MethodSource("provideDataForStreamOfExample")
public void parameterizedTestsForStreamOfExample(BaseStreamExample baseStreamExample, java.lang.Integer[] integerArray, Stream expectedResult) {
Stream actual = baseStreamExample.streamOfExample(integerArray);
if (expectedResult == null) {
assertNull(actual);
} else {
assertTrue(deepEquals(expectedResult, actual));
}
}
///endregion
///endregion
///region Data providers and utils methods
public static java.util.ArrayList provideDataForStreamOfExample() {
ArrayList argList = new ArrayList();
<...>
return argList;
}
<...>
}
Additional details
Cause reason is generic execution selection heuristics. When selecting it we do not depend on result type fullness (whether it is empty array or filled array, it does not matter right now). In our case we have three collected executions, but we select execution with empty values array. That is why the else-branch is empty. Deep equals does not know how to compare empty arrays, lists, etc.
As suggestions there are two options:
- Adapt generic execution selection,
- Render assertTrue(deepEquals(expectedResult, actual)) or assertNotNull(actual) every time,
- If possible, check else-branch body absence beforehand, and choose not empty if there is one among all executions.
Description
Generating test for
streamOfExamplemethod results in different outcomes when generating inrunIdeand as asample.RunIdeversion has empty else branch.Also, it's important to notice that there are different
actualandexpectedResulttypes (Object vs. Stream).To Reproduce
runIde, generate parametrized test forstreamOfExample,BaseStreamExampleTestas a sample (not inrunIde),Actual behavior
in

runIde:as a
sample:Additional details
Cause reason is generic execution selection heuristics. When selecting it we do not depend on result type fullness (whether it is empty array or filled array, it does not matter right now). In our case we have three collected executions, but we select execution with empty values array. That is why the else-branch is empty. Deep equals does not know how to compare empty arrays, lists, etc.
As suggestions there are two options: