Skip to content

Compare returning expected and actual Stream #1046

Open

Description

@alisevych

Description

Tests on methods returning Stream contain actual and expected results, but do not have any assertions to compare them.

To Reproduce

  1. Run the 'UTBotJava' project in IntelliJ Idea 2022.1.4
  2. Install one of the latest from main branch
  3. Open test generation dialog for utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java
  4. Select returningStreamExample method
  5. click Generate Tests
  6. check generated tests

Expected behavior

Need to compare expected and actual results for Streams in tests.

Actual behavior

There are actual and expected Objects generated containing Streams. But they are not compared.

Visual proofs (screenshots, logs, images)

package org.utbot.examples.stream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;

import java.util.ArrayList;
import java.util.List;

import static org.utbot.runtime.utils.UtUtils.createInstance;

public class BaseStreamExampleTest {
    ///region Test suites for executable org.utbot.examples.stream.BaseStreamExample.returningStreamExample

    ///region SYMBOLIC EXECUTION ENGINE: SUCCESSFUL EXECUTIONS for method returningStreamExample(java.util.List)

    /**
     * @utbot.classUnderTest {@link BaseStreamExample}
     * @utbot.methodUnderTest {@link BaseStreamExample#returningStreamExample(List)}
     * @utbot.executesCondition {@code (list.isEmpty()): True}
     * @utbot.invokes {@code {@link List#stream()}}
     * @utbot.returnsFrom {@code return list.stream();}
     */
    @Test
    @DisplayName("returningStreamExample: list.isEmpty() : True -> return list.stream()")
    public void testReturningStreamExample_ListIsEmpty() throws Exception {
        BaseStreamExample baseStreamExample = new BaseStreamExample();
        ArrayList list = new ArrayList();

        Object actual = baseStreamExample.returningStreamExample(list);

        Object expected = createInstance("java.util.stream.ReferencePipeline$Head");
    }

    /**
     * @utbot.classUnderTest {@link BaseStreamExample}
     * @utbot.methodUnderTest {@link BaseStreamExample#returningStreamExample(List)}
     * @utbot.executesCondition {@code (list.isEmpty()): False}
     * @utbot.invokes {@code {@link List#stream()}}
     * @utbot.returnsFrom {@code return list.stream();}
     */
    @Test
    @DisplayName("returningStreamExample: list.isEmpty() : False -> return list.stream()")
    public void testReturningStreamExample_NotListIsEmpty() throws Exception {
        BaseStreamExample baseStreamExample = new BaseStreamExample();
        ArrayList list = new ArrayList();
        list.add(null);
        list.add(null);
        list.add(null);
        list.add(null);
        list.add(null);
        list.add(null);
        list.add(null);
        list.add(null);
        list.add(null);
        list.add(null);

        Object actual = baseStreamExample.returningStreamExample(list);

        Object expected = createInstance("java.util.stream.ReferencePipeline$Head");
    }
    ///endregion

    ///endregion
}

Environment

Windows 10 Pro
Gradle
JDK 11

Additional context

Probably related to #1034

Same for DoubleStreamExample.returningStreamExample

Activity

  1. changed the title [-]Compare returning expected and actual Stream when returned from a method[/-] [+]Compare returning expected and actual Stream[/+] on Sep 30, 2022
  2. moved this to Todo in UTBot Javaon Sep 30, 2022
  3. alisevych commented on Sep 30, 2022

    @alisevych
    MemberAuthor

    @Damtev @EgorkaKulikov
    Could you please share your view on the generated tests on Streams? And on Functional interfaces too?
    It seems that we need to add some verification of user's code. Comparing objects in a Stream or making some other checks.

  4. alisevych commented on Oct 3, 2022

    @alisevych
    MemberAuthor

    @Damtev Please pay attention that in second test expected field is not equal to actual : it is empty.

  5. added
    comp-codegenIssue is related to code generator
    lang-javaIssue is related to Java support
    on Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-codegenIssue is related to code generatorctg-bugIssue is a buglang-javaIssue is related to Java support

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions