Skip to content

Casting problems in parametrized test generation #626

Closed
@sofurihafe

Description

@sofurihafe

Description

There are problems with class casting in parametrized test generation.
Seems like the problem is connected with general execution selection.
Suggestion is to generate separated tests in cases like these.

To Reproduce

  1. Enable parametrized test generation for samples,
  2. Run InstanceOfExampleTest.

Actual behavior

testObjectInstanceOfArray

Problem may be with AssertArrayEquals trying to cast boolean array to integer array.
Generated parametrized test looks like this:

public class InstanceOfExampleGeneratedTest {
    ///region Test suites for executable org.utbot.examples.casts.InstanceOfExample.objectInstanceOfArray
    
    ///region Parameterized test for method objectInstanceOfArray(java.lang.Object)
    
    @ParameterizedTest
    @MethodSource("provideDataForObjectInstanceOfArray")
    public void parameterizedTestsForObjectInstanceOfArray(InstanceOfExample instanceOfExample, Object object, Object expectedResult) {
        Object actual = instanceOfExample.objectInstanceOfArray(object);
        
        if (expectedResult == null) {
            assertNull(actual);
        } else {
            
            int expectedResultSize = getArrayLength(expectedResult);
            assertEquals(expectedResultSize, getArrayLength(actual));
            assertArrayEquals(((int[]) expectedResult), ((int[]) actual));
        }
    }
    ///endregion
    
    ///endregion
    
    ///region Data providers and utils methods
    
    public static java.util.ArrayList<org.junit.jupiter.params.provider.Arguments> provideDataForObjectInstanceOfArray() {
        java.util.ArrayList<org.junit.jupiter.params.provider.Arguments> argList = new java.util.ArrayList<org.junit.jupiter.params.provider.Arguments>();
        
        <...>

        {
            InstanceOfExample instanceOfExample = new InstanceOfExample();
            boolean[] booleanArray = {false};
            
            argList.add(org.junit.jupiter.params.provider.Arguments.arguments(instanceOfExample, booleanArray, booleanArray));
        }

        <...>
        
        return argList;
    }
    
    private static int getArrayLength(Object arr) {
        return java.lang.reflect.Array.getLength(arr);
    }
    ///endregion
}

testInstanceOfObjectArray

Problem may be with AssertArrayEquals trying to cast single array to triple array.
Generated parametrized test looks like this:

public class InstanceOfExampleGeneratedTest {
    ///region Test suites for executable org.utbot.examples.casts.InstanceOfExample.instanceOfObjectArray
    
    ///region Parameterized test for method instanceOfObjectArray(java.lang.Object[])
    
    @ParameterizedTest
    @MethodSource("provideDataForInstanceOfObjectArray")
    public void parameterizedTestsForInstanceOfObjectArray(InstanceOfExample instanceOfExample, java.lang.Object[] objectArray, java.lang.Object[] expectedResult) {
        java.lang.Object[] actual = instanceOfExample.instanceOfObjectArray(objectArray);
        
        if (expectedResult == null) {
            assertNull(actual);
        } else {
            
            int expectedResultSize = expectedResult.length;
            assertEquals(expectedResultSize, actual.length);
            assertArrayEquals(((int[][][]) expectedResult), ((int[][][]) actual));
        }
    }
    ///endregion
    
    ///endregion
    
    ///region Data providers and utils methods
    
    public static java.util.ArrayList<org.junit.jupiter.params.provider.Arguments> provideDataForInstanceOfObjectArray() {
        java.util.ArrayList<org.junit.jupiter.params.provider.Arguments> argList = new java.util.ArrayList<org.junit.jupiter.params.provider.Arguments>();
        
        <...>

        {
            InstanceOfExample instanceOfExample = new InstanceOfExample();
            java.lang.Object[] objectArray = {null, null};
            
            argList.add(org.junit.jupiter.params.provider.Arguments.arguments(instanceOfExample, objectArray, objectArray));
        }
        
        return argList;
    }
    ///endregion
}

Visual proofs (screenshots, logs, images)

testObjectInstanceOfArray

Same as the following

testInstanceOfObjectArray

image

Metadata

Metadata

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions