Generated Unit tests file is showing errors and it gives compilation error

Let me know if I need to provide any more information.

Hi @Pallav_Kumar

Thanks for trying Diffblue Cover and for getting in touch.
By default, Diffblue Cover CLI writes unit tests which both compile and pass by validating them before the creation process has finished. On the other hand, the IntelliJ plugin does not validate the unit tests created. This maximizes the number of tests created and may leave some “partial” unit tests for the developer to complete. This behaviour is completely configurable via the plugin settings (in IntelliJ: Diffblue → Change Settings → Test Creation → Partial Test Creation).
For your reference, please see Creating Partial Tests in the Diffblue documentation, which explains how to change the configuration of this feature.

Best regards
Peter

Thanks @petersear for the information. But as per the Partial Test Creation settings, if any generated tests comes under partial tests then //TODO with different annotation should be marked on those tests but I don’t see any such on my generated tests.


Let me know if my understanding is correct.

Update: I tried generating tests with all Partial Tests setting unchecked, even then it is generating tests which is having compilation error.

Hi Pallav
Thanks for this extra information. Would you be able to share the contents of the non-compiling test method? We would like to investigate further to understand what is happening and to help you move past this.
If you could also share the Diffblue support log file, that will be a great help.
Best regards
Peter

Sure I will share that. Few more information’s to add.

  1. The java class on which I am trying to generate tests have only 1 public method and rest all are private methods.
  2. Line coverage seems to be very less with generated UTs.
  3. All generated UTs have compilation issue due to same reason.

support.log (112.9 KB)
Please find the support log.

    /**
     * Method under test:
     * {@link JourneyVersionValidationService#validateVersionForStructuralChanges(JourneyMetaVersionRO, JourneyMetaVersionRO)}
     */
    @Test
    void testValidateVersionForStructuralChanges() {
        // Arrange
        ArrayList<JourneyBlock> journeyBlockList = new ArrayList<>();
        journeyBlockList.add(new CounterBlock());
        JourneyMetaVersion journeyMetaVersion = mock(JourneyMetaVersion.class);
        when(journeyMetaVersion.getJourneyBlocks()).thenReturn(journeyBlockList);
        doNothing().when(journeyMetaVersion).setApprovedBy(anyLong());
        doNothing().when(journeyMetaVersion).setAuditInfo(Mockito.<List<JourneyAuditInfo>>any());
        doNothing().when(journeyMetaVersion).setConsentStatusForPreviousVersion(Mockito.<JourneyMeta.JourneyStatus>any());
        doNothing().when(journeyMetaVersion).setCreatedBy(anyLong());
        doNothing().when(journeyMetaVersion).setEndType(Mockito.<EndType>any());
        doNothing().when(journeyMetaVersion).setEndsAt(Mockito.<Date>any());
        doNothing().when(journeyMetaVersion).setErrorCode(Mockito.<ErrorCodes>any());
        doNothing().when(journeyMetaVersion).setErrorMessage(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setEventForestSubscription(Mockito.<EventForestSubscription>any());
        doNothing().when(journeyMetaVersion).setExitTriggerBlockId(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setId(Mockito.<String>any());
        //doNothing().when(journeyMetaVersion).setJourneyBlocks(Mockito
        // .<List<JourneyBlock<Object>>>any());
        doNothing().when(journeyMetaVersion).setJourneyMetaContext(Mockito.<JourneyMetaContext>any());
        doNothing().when(journeyMetaVersion).setJourneyMetaGroupId(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setJourneyMetaId(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setJourneySetting(Mockito.<JourneySetting>any());
        doNothing().when(journeyMetaVersion).setJourneyStatus(Mockito.<JourneyMeta.JourneyStatus>any());
        doNothing().when(journeyMetaVersion).setJourneyVersion(anyInt());
        doNothing().when(journeyMetaVersion).setLastUpdatedTime(Mockito.<Date>any());
        doNothing().when(journeyMetaVersion).setLevel(Mockito.<JourneyPresetTemplate.JourneyLevel>any());
        doNothing().when(journeyMetaVersion).setName(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setOrgId(anyLong());
        doNothing().when(journeyMetaVersion).setPreCheckErrors(Mockito.<List<ValidationError>>any());
        doNothing().when(journeyMetaVersion).setStartType(Mockito.<StartType>any());
        doNothing().when(journeyMetaVersion).setStartsFrom(Mockito.<Date>any());
        doNothing().when(journeyMetaVersion).setVersion(anyInt());
        journeyMetaVersion.setApprovedBy(1L);
        journeyMetaVersion.setAuditInfo(new ArrayList<>());
        journeyMetaVersion.setConsentStatusForPreviousVersion(JourneyMeta.JourneyStatus.DRAFT);
        journeyMetaVersion.setCreatedBy(1L);
        journeyMetaVersion.setEndType(EndType.NEVER);
        journeyMetaVersion.setEndsAt(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()));
        journeyMetaVersion.setErrorCode(ErrorCodes.UNABLE_GET_LOCK);
        journeyMetaVersion.setErrorMessage("An error occurred");
        EventForestSubscription eventForestSubscription = EventForestSubscription.builder()
                .subscriptionId("42")
                .subscriptionStatus(EventForestSubscription.SubscriptionStatus.ACTIVE)
                .build();
        journeyMetaVersion.setEventForestSubscription(eventForestSubscription);
        journeyMetaVersion.setExitTriggerBlockId("42");
        journeyMetaVersion.setId("42");
        journeyMetaVersion.setJourneyBlocks(new ArrayList<>());
        JourneyMetaContext.JourneyMetaContextBuilder builderResult = JourneyMetaContext.builder();
        JourneyMetaContext journeyMetaContext = builderResult.sourceJourneyMetas(new ArrayList<>()).build();
        journeyMetaVersion.setJourneyMetaContext(journeyMetaContext);
        journeyMetaVersion.setJourneyMetaGroupId("42");
        journeyMetaVersion.setJourneyMetaId("42");
        JourneySetting.JourneySettingBuilder builderResult2 = JourneySetting.builder();
        JourneySetting journeySetting = builderResult2.capping(new JourneyCapping())
                .encryptUrl(true)
                .linkTrackingEnabled(true)
                .multiEntryAllowed(true)
                .simulationMode(true)
                .testControlModeDisabled(true)
                .timeCompressionFactor(10.0d)
                .useTinyUrl(true)
                .build();
        journeyMetaVersion.setJourneySetting(journeySetting);
        journeyMetaVersion.setJourneyStatus(JourneyMeta.JourneyStatus.DRAFT);
        journeyMetaVersion.setJourneyVersion(1);
        journeyMetaVersion
                .setLastUpdatedTime(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()));
        journeyMetaVersion.setLevel(JourneyPresetTemplate.JourneyLevel.CUSTOMER);
        journeyMetaVersion.setName("Name");
        journeyMetaVersion.setOrgId(1L);
        journeyMetaVersion.setPreCheckErrors(new ArrayList<>());
        journeyMetaVersion.setStartType(StartType.IMMEDIATE);
        journeyMetaVersion
                .setStartsFrom(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()));
        journeyMetaVersion.setVersion(1);
        JourneyMetaVersionRO currentJourneyMetaVersion = mock(JourneyMetaVersionRO.class);
        when(currentJourneyMetaVersion.toBO()).thenReturn(journeyMetaVersion);
        doNothing().when(currentJourneyMetaVersion).setSchedule(Mockito.<ScheduleRO>any());
        ScheduleRO schedule = ScheduleRO.builder()
                .endType(EndType.PARTICULAR_DATE)
                .endsAt(1L)
                .startType(StartType.IMMEDIATE)
                .startsFrom(1L)
                .build();
        currentJourneyMetaVersion.setSchedule(schedule);

        // Act
        List<JourneyMetaValidationError> actualValidateVersionForStructuralChangesResult = journeyVersionValidationService
                .validateVersionForStructuralChanges(currentJourneyMetaVersion, new JourneyMetaVersionRO());

        // Assert
        verify(currentJourneyMetaVersion).setSchedule(Mockito.<ScheduleRO>any());
        verify(currentJourneyMetaVersion).toBO();
        verify(journeyMetaVersion).getJourneyBlocks();
        verify(journeyMetaVersion).setApprovedBy(anyLong());
        verify(journeyMetaVersion).setAuditInfo(Mockito.<List<JourneyAuditInfo>>any());
        verify(journeyMetaVersion).setConsentStatusForPreviousVersion(Mockito.<JourneyMeta.JourneyStatus>any());
        verify(journeyMetaVersion).setCreatedBy(anyLong());
        verify(journeyMetaVersion).setEndType(Mockito.<EndType>any());
        verify(journeyMetaVersion).setEndsAt(Mockito.<Date>any());
        verify(journeyMetaVersion).setErrorCode(Mockito.<ErrorCodes>any());
        verify(journeyMetaVersion).setErrorMessage(Mockito.<String>any());
        verify(journeyMetaVersion).setEventForestSubscription(Mockito.<EventForestSubscription>any());
        verify(journeyMetaVersion).setExitTriggerBlockId(Mockito.<String>any());
        verify(journeyMetaVersion).setId(Mockito.<String>any());
        //verify(journeyMetaVersion).setJourneyBlocks(Mockito.<List<JourneyBlock<Object>>>any());
        verify(journeyMetaVersion).setJourneyMetaContext(Mockito.<JourneyMetaContext>any());
        verify(journeyMetaVersion).setJourneyMetaGroupId(Mockito.<String>any());
        verify(journeyMetaVersion).setJourneyMetaId(Mockito.<String>any());
        verify(journeyMetaVersion).setJourneySetting(Mockito.<JourneySetting>any());
        verify(journeyMetaVersion).setJourneyStatus(Mockito.<JourneyMeta.JourneyStatus>any());
        verify(journeyMetaVersion).setJourneyVersion(anyInt());
        verify(journeyMetaVersion).setLastUpdatedTime(Mockito.<Date>any());
        verify(journeyMetaVersion).setLevel(Mockito.<JourneyPresetTemplate.JourneyLevel>any());
        verify(journeyMetaVersion).setName(Mockito.<String>any());
        verify(journeyMetaVersion).setOrgId(anyLong());
        verify(journeyMetaVersion).setPreCheckErrors(Mockito.<List<ValidationError>>any());
        verify(journeyMetaVersion).setStartType(Mockito.<StartType>any());
        verify(journeyMetaVersion).setStartsFrom(Mockito.<Date>any());
        verify(journeyMetaVersion).setVersion(anyInt());
        JourneyMetaValidationError getResult = actualValidateVersionForStructuralChangesResult.get(0);
        assertEquals("numbers of block mismatch with the previous version", getResult.getErrorMessage());
        assertNull(getResult.getParameters());
        assertNull(getResult.getConditionIndex());
        assertNull(getResult.getBlockId());
        assertEquals(1, actualValidateVersionForStructuralChangesResult.size());
    }
Error details : 
**Bound mismatch: The type Object is not a valid substitute for the bounded parameter <T extends RO> of the type JourneyBlock<T>**
Currently I have commented the lines which are causing compilation error. Exact error I had attached in my first screeshot.. Diffblue cover had generated 5 testcases and all have similar issue.  Please let me know if any more information is needed.

Thanks.

Also Attaching the coverage report of generated test class and actual test class which we had written. We don’t expect the tool to have same level of coverage but want to understand the reason for less coverage too.


There was a code part I had added as seperate reply but I guess on edit and same that got deleted.

Adding it again here.

/**
     * Method under test:
     * {@link JourneyVersionValidationService#validateVersionForStructuralChanges(JourneyMetaVersionRO, JourneyMetaVersionRO)}
     */
    @Test
    void testValidateVersionForStructuralChanges2() {
        // Arrange
        JourneyMetaVersion journeyMetaVersion = mock(JourneyMetaVersion.class);
        when(journeyMetaVersion.getJourneyBlocks()).thenReturn(new ArrayList<>());
        doNothing().when(journeyMetaVersion).setApprovedBy(anyLong());
        doNothing().when(journeyMetaVersion).setAuditInfo(Mockito.<List<JourneyAuditInfo>>any());
        doNothing().when(journeyMetaVersion).setConsentStatusForPreviousVersion(Mockito.<JourneyMeta.JourneyStatus>any());
        doNothing().when(journeyMetaVersion).setCreatedBy(anyLong());
        doNothing().when(journeyMetaVersion).setEndType(Mockito.<EndType>any());
        doNothing().when(journeyMetaVersion).setEndsAt(Mockito.<Date>any());
        doNothing().when(journeyMetaVersion).setErrorCode(Mockito.<ErrorCodes>any());
        doNothing().when(journeyMetaVersion).setErrorMessage(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setEventForestSubscription(Mockito.<EventForestSubscription>any());
        doNothing().when(journeyMetaVersion).setExitTriggerBlockId(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setId(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setJourneyBlocks(Mockito.<List<JourneyBlock<Object>>>any());
        doNothing().when(journeyMetaVersion).setJourneyMetaContext(Mockito.<JourneyMetaContext>any());
        doNothing().when(journeyMetaVersion).setJourneyMetaGroupId(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setJourneyMetaId(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setJourneySetting(Mockito.<JourneySetting>any());
        doNothing().when(journeyMetaVersion).setJourneyStatus(Mockito.<JourneyMeta.JourneyStatus>any());
        doNothing().when(journeyMetaVersion).setJourneyVersion(anyInt());
        doNothing().when(journeyMetaVersion).setLastUpdatedTime(Mockito.<Date>any());
        doNothing().when(journeyMetaVersion).setLevel(Mockito.<JourneyPresetTemplate.JourneyLevel>any());
        doNothing().when(journeyMetaVersion).setName(Mockito.<String>any());
        doNothing().when(journeyMetaVersion).setOrgId(anyLong());
        doNothing().when(journeyMetaVersion).setPreCheckErrors(Mockito.<List<ValidationError>>any());
        doNothing().when(journeyMetaVersion).setStartType(Mockito.<StartType>any());
        doNothing().when(journeyMetaVersion).setStartsFrom(Mockito.<Date>any());
        doNothing().when(journeyMetaVersion).setVersion(anyInt());
        journeyMetaVersion.setApprovedBy(1L);
        journeyMetaVersion.setAuditInfo(new ArrayList<>());
        journeyMetaVersion.setConsentStatusForPreviousVersion(JourneyMeta.JourneyStatus.DRAFT);
        journeyMetaVersion.setCreatedBy(1L);
        journeyMetaVersion.setEndType(EndType.NEVER);
        journeyMetaVersion.setEndsAt(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()));
        journeyMetaVersion.setErrorCode(ErrorCodes.UNABLE_GET_LOCK);
        journeyMetaVersion.setErrorMessage("An error occurred");
        EventForestSubscription eventForestSubscription = EventForestSubscription.builder()
                .subscriptionId("42")
                .subscriptionStatus(EventForestSubscription.SubscriptionStatus.ACTIVE)
                .build();
        journeyMetaVersion.setEventForestSubscription(eventForestSubscription);
        journeyMetaVersion.setExitTriggerBlockId("42");
        journeyMetaVersion.setId("42");
        journeyMetaVersion.setJourneyBlocks(new ArrayList<>());
        JourneyMetaContext.JourneyMetaContextBuilder builderResult = JourneyMetaContext.builder();
        JourneyMetaContext journeyMetaContext = builderResult.sourceJourneyMetas(new ArrayList<>()).build();
        journeyMetaVersion.setJourneyMetaContext(journeyMetaContext);
        journeyMetaVersion.setJourneyMetaGroupId("42");
        journeyMetaVersion.setJourneyMetaId("42");
        JourneySetting.JourneySettingBuilder builderResult2 = JourneySetting.builder();
        JourneySetting journeySetting = builderResult2.capping(new JourneyCapping())
                .encryptUrl(true)
                .linkTrackingEnabled(true)
                .multiEntryAllowed(true)
                .simulationMode(true)
                .testControlModeDisabled(true)
                .timeCompressionFactor(10.0d)
                .useTinyUrl(true)
                .build();
        journeyMetaVersion.setJourneySetting(journeySetting);
        journeyMetaVersion.setJourneyStatus(JourneyMeta.JourneyStatus.DRAFT);
        journeyMetaVersion.setJourneyVersion(1);
        journeyMetaVersion
                .setLastUpdatedTime(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()));
        journeyMetaVersion.setLevel(JourneyPresetTemplate.JourneyLevel.CUSTOMER);
        journeyMetaVersion.setName("Name");
        journeyMetaVersion.setOrgId(1L);
        journeyMetaVersion.setPreCheckErrors(new ArrayList<>());
        journeyMetaVersion.setStartType(StartType.IMMEDIATE);
        journeyMetaVersion
                .setStartsFrom(Date.from(LocalDate.of(1970, 1, 1).atStartOfDay().atZone(ZoneOffset.UTC).toInstant()));
        journeyMetaVersion.setVersion(1);
        JourneyMetaVersionRO currentJourneyMetaVersion = mock(JourneyMetaVersionRO.class);
        ScheduleRO buildResult = ScheduleRO.builder()
                .endType(EndType.NEVER)
                .endsAt(1L)
                .startType(StartType.IMMEDIATE)
                .startsFrom(1L)
                .build();
        when(currentJourneyMetaVersion.getSchedule()).thenReturn(buildResult);
        when(currentJourneyMetaVersion.toBO()).thenReturn(journeyMetaVersion);
        doNothing().when(currentJourneyMetaVersion).setSchedule(Mockito.<ScheduleRO>any());
        ScheduleRO schedule = ScheduleRO.builder()
                .endType(EndType.PARTICULAR_DATE)
                .endsAt(1L)
                .startType(StartType.IMMEDIATE)
                .startsFrom(1L)
                .build();
        currentJourneyMetaVersion.setSchedule(schedule);

        JourneyMetaVersionRO newJourneyMetaVersion = new JourneyMetaVersionRO();
        ScheduleRO schedule2 = ScheduleRO.builder()
                .endType(EndType.NEVER)
                .endsAt(1L)
                .startType(StartType.IMMEDIATE)
                .startsFrom(1L)
                .build();
        newJourneyMetaVersion.setSchedule(schedule2);

        // Act
        List<JourneyMetaValidationError> actualValidateVersionForStructuralChangesResult = journeyVersionValidationService
                .validateVersionForStructuralChanges(currentJourneyMetaVersion, newJourneyMetaVersion);

        // Assert
        verify(currentJourneyMetaVersion, atLeast(1)).getSchedule();
        verify(currentJourneyMetaVersion).setSchedule(Mockito.<ScheduleRO>any());
        verify(currentJourneyMetaVersion).toBO();
        verify(journeyMetaVersion).getJourneyBlocks();
        verify(journeyMetaVersion).setApprovedBy(anyLong());
        verify(journeyMetaVersion).setAuditInfo(Mockito.<List<JourneyAuditInfo>>any());
        verify(journeyMetaVersion).setConsentStatusForPreviousVersion(Mockito.<JourneyMeta.JourneyStatus>any());
        verify(journeyMetaVersion).setCreatedBy(anyLong());
        verify(journeyMetaVersion).setEndType(Mockito.<EndType>any());
        verify(journeyMetaVersion).setEndsAt(Mockito.<Date>any());
        verify(journeyMetaVersion).setErrorCode(Mockito.<ErrorCodes>any());
        verify(journeyMetaVersion).setErrorMessage(Mockito.<String>any());
        verify(journeyMetaVersion).setEventForestSubscription(Mockito.<EventForestSubscription>any());
        verify(journeyMetaVersion).setExitTriggerBlockId(Mockito.<String>any());
        verify(journeyMetaVersion).setId(Mockito.<String>any());
        verify(journeyMetaVersion).setJourneyBlocks(Mockito.<List<JourneyBlock<Object>>>any());
        verify(journeyMetaVersion).setJourneyMetaContext(Mockito.<JourneyMetaContext>any());
        verify(journeyMetaVersion).setJourneyMetaGroupId(Mockito.<String>any());
        verify(journeyMetaVersion).setJourneyMetaId(Mockito.<String>any());
        verify(journeyMetaVersion).setJourneySetting(Mockito.<JourneySetting>any());
        verify(journeyMetaVersion).setJourneyStatus(Mockito.<JourneyMeta.JourneyStatus>any());
        verify(journeyMetaVersion).setJourneyVersion(anyInt());
        verify(journeyMetaVersion).setLastUpdatedTime(Mockito.<Date>any());
        verify(journeyMetaVersion).setLevel(Mockito.<JourneyPresetTemplate.JourneyLevel>any());
        verify(journeyMetaVersion).setName(Mockito.<String>any());
        verify(journeyMetaVersion).setOrgId(anyLong());
        verify(journeyMetaVersion).setPreCheckErrors(Mockito.<List<ValidationError>>any());
        verify(journeyMetaVersion).setStartType(Mockito.<StartType>any());
        verify(journeyMetaVersion).setStartsFrom(Mockito.<Date>any());
        verify(journeyMetaVersion).setVersion(anyInt());
        assertTrue(actualValidateVersionForStructuralChangesResult.isEmpty());
    }


Below lines have issue :
doNothing().when(journeyMetaVersion).setJourneyBlocks(Mockito.<List<JourneyBlock>>any());
verify(journeyMetaVersion).setJourneyBlocks(Mockito.<List<JourneyBlock>>any());

Issue Details :
Bound mismatch: The type Object is not a valid substitute for the bounded parameter of the type JourneyBlock

Any update on this? @petersear

Hi @Pallav_Kumar
Thanks for adding the details requested.
We believe this to be related to the selection of type instantiations. In order for us to understand more about the context so that we can help further, would you be able to share the type parameters of the class JourneyBlock? This will be something like public class JourneyBlock<T extends Something> {. In particular, we are interested in the part between < and >.
Best regards
Peter

public abstract class JourneyBlock<T extends RO> implements BO<T>

@petersear

Hi @Pallav_Kumar
Thanks for sending this information. Can you tell us more about what the objects R0 and B0 are? They do not appear to be referenced in the log file you sent us. Knowing more about these, particularly R0, will help us to understand what is happening.
Best regards
Peter