Closed
Description
To Reproduce
- Enable parametrized test generation for samples,
- Run
InstanceOfExampleTest
.
Actual behavior
Generated parametrized
test looks like this:
public class InstanceOfExampleGeneratedTest {
///region Test suites for executable org.utbot.examples.casts.InstanceOfExample.symbolicInstanceOf
///region Parameterized test for method symbolicInstanceOf(org.utbot.examples.casts.CastClass[], int)
@ParameterizedTest
@MethodSource("provideDataForSymbolicInstanceOf")
public void parameterizedTestsForSymbolicInstanceOf(InstanceOfExample instanceOfExample,
org.utbot.examples.casts.CastClass[] castClassArray,
int int1,
CastClass expectedResult,
Class<Throwable> expectedError
) throws IllegalAccessException, NoSuchFieldException {
try {
CastClass actual = instanceOfExample.symbolicInstanceOf(castClassArray, int1);
if (expectedResult == null) {
assertNull(actual);
} else {
int expectedResultZ = ((Integer) getFieldValue(expectedResult, "z"));
int actualZ = ((Integer) getFieldValue(actual, "z"));
assertEquals(expectedResultZ, actualZ);
int expectedResultX = expectedResult.x;
int actualX = actual.x;
assertEquals(expectedResultX, actualX);
int expectedResultDefaultValue = expectedResult.defaultValue;
int actualDefaultValue = actual.defaultValue;
assertEquals(expectedResultDefaultValue, actualDefaultValue);
}
} catch (java.lang.Throwable throwable) {
assertTrue(expectedError.isInstance(throwable));
}
}
///endregion
///endregion
///region Data providers and utils methods
public static java.util.ArrayList<org.junit.jupiter.params.provider.Arguments> provideDataForSymbolicInstanceOf() {
java.util.ArrayList<org.junit.jupiter.params.provider.Arguments> argList = new java.util.ArrayList<org.junit.jupiter.params.provider.Arguments>();
<...>
{
InstanceOfExample instanceOfExample = new InstanceOfExample();
org.utbot.examples.casts.CastClass[] castClassArray = {null, null};
CastClassSecondSucc castClassSecondSucc = new CastClassSecondSucc();
castClassSecondSucc.d = 20;
castClassSecondSucc.defaultValue = 5;
argList.add(org.junit.jupiter.params.provider.Arguments.arguments(instanceOfExample, castClassArray, 1, castClassSecondSucc, null));
}
<...>
return argList;
}
private static Object getFieldValue(Object obj, String fieldName) throws IllegalAccessException, NoSuchFieldException {
<...>
}
///endregion
}
The problem is that a field z
is a field of CastClassFirstSucc
class, but provided class is CastClassSecondSucc
, which has d
field. So getFieldValue
fails.
Expected behavior
Currently there are two ideas:
- Create a separate parametrized test for each type of expected result in executions
- If there is a class that is a subtype of all result classes (e.g.
CastClassSecondSucc
is an inheritor of not onlyCastClass
but aCastClassFirstSucc
also), we can use it inarbitraryExecution
.
Metadata
Metadata
Assignees
Type
Projects
Status
Todo