Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Other class is not mocked as required #747

Closed
Tracked by #1187
alisevych opened this issue Aug 19, 2022 · 1 comment · Fixed by #1033
Closed
Tracked by #1187

Other class is not mocked as required #747

alisevych opened this issue Aug 19, 2022 · 1 comment · Fixed by #1033
Assignees
Labels
ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one

Comments

@alisevych
Copy link
Member

alisevych commented Aug 19, 2022

Description

When Mocking strategy is set to "Other classes: Mockito" - other classes should be mocked in all tests.

To Reproduce

Steps to reproduce the behavior:

  1. Run IntelliJ IDEA 2022.1.4 with one of the latest builds of UTBot plugin from main branch installed.
  2. Open UTBotJava project
  3. Find utbot-sample/src/main/java/org/utbot/examples/mock/CommonMocksExample.java
  4. Generate tests for nextValue() method with Mocking strategy is set to "Other classes: Mockito"
  5. Open the generated test

Expected behavior

RecursiveTypeClass used as the input parameter of the method is supposed to be mocked in all tests - except the one with null used.

Actual behavior

There are 4 tests generated. RecursiveTypeClass is mocked only in one test.

Visual proofs (screenshots, logs, images)

public class CommonMocksExampleTest {

    @Test
    public void testNextValue() {
        CommonMocksExample commonMocksExample = new CommonMocksExample();
        RecursiveTypeClass node = new RecursiveTypeClass();
        RecursiveTypeClass recursiveTypeClass = new RecursiveTypeClass();
        recursiveTypeClass.next = null;
        recursiveTypeClass.value = 0;
        node.next = recursiveTypeClass;
        node.value = 0;

        RecursiveTypeClass actual = commonMocksExample.nextValue(node);

        RecursiveTypeClass nodeNext = node.next;
        RecursiveTypeClass actualNext = actual.next;
        RecursiveTypeClass actualNextNext = actualNext.next;
        assertNull(actualNextNext);

        int nodeNextValue = nodeNext.value;
        int actualNextValue = actualNext.value;
        assertEquals(nodeNextValue, actualNextValue);

        int nodeValue = node.value;
        int actualValue = actual.value;
        assertEquals(nodeValue, actualValue);
    }

    @Test
    public void testNextValueThrowsNPE() {
        CommonMocksExample commonMocksExample = new CommonMocksExample();
        RecursiveTypeClass node = new RecursiveTypeClass();
        
        /* This test fails because method [org.utbot.examples.mock.CommonMocksExample.nextValue] produces [java.lang.NullPointerException]
            org.utbot.examples.mock.CommonMocksExample.nextValue(CommonMocksExample.java:25) */
        commonMocksExample.nextValue(node);
    }

    @Test
    public void testNextValue_NodeNextEqualsNode() {
        CommonMocksExample commonMocksExample = new CommonMocksExample();
        RecursiveTypeClass nodeMock = mock(RecursiveTypeClass.class);
        nodeMock.next = nodeMock;

        RecursiveTypeClass actual = commonMocksExample.nextValue(nodeMock);

        int nodeMockValue = nodeMock.value;
        int actualValue = actual.value;
        assertEquals(nodeMockValue, actualValue);
    }

    @Test
    public void testNextValue_ThrowNullPointerException() {
        CommonMocksExample commonMocksExample = new CommonMocksExample();
        
        /* This test fails because method [org.utbot.examples.mock.CommonMocksExample.nextValue] produces [java.lang.NullPointerException]
            org.utbot.examples.mock.CommonMocksExample.nextValue(CommonMocksExample.java:21) */
        commonMocksExample.nextValue(null);
    }

}

Environment

Windows 10 Pro
Gradle project
JDK 8

Additional context

When generating tests for MockWithFieldExample with same setting : Other classes : Mockito - VersionStamp is not mocked either

@korifey korifey moved this to Todo in UTBot Java Aug 19, 2022
@alisevych alisevych added the ctg-bug Issue is a bug label Aug 19, 2022
@alisevych alisevych added this to the Release preparation milestone Sep 7, 2022
@CaelmBleidd
Copy link
Member

I checked it. There are two important points:

  1. At the moment, I have four executions for this test at the latest master: two symbolic and two made by fuzzer, although we had all four made by the symbolic engine. I'm not sure whether it is expected behaviour or not, maybe @dtim has something to say about it;
  2. Seems like the fuzzer doesn't know anything about the mock strategy, therefore it generates tests without them (for example, the longest method is made by the fuzzer). So, I think I can reassign this issue to @Markoutte since it is not the engine's mistake

@CaelmBleidd CaelmBleidd assigned Markoutte and unassigned CaelmBleidd Sep 14, 2022
@alisevych alisevych removed this from the Release preparation milestone Sep 28, 2022
@alisevych alisevych added the spec-release-tailings Failed to include in the current release, let's include it in the next one label Sep 29, 2022
@alisevych alisevych added this to the 2022.12 Release milestone Oct 7, 2022
Repository owner moved this from Todo to Done in UTBot Java Oct 11, 2022
AbdullinAM pushed a commit to AbdullinAM/UTBotJava that referenced this issue Oct 17, 2022
AbdullinAM pushed a commit to AbdullinAM/UTBotJava that referenced this issue Oct 17, 2022
@Markoutte Markoutte mentioned this issue Dec 6, 2022
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants