Skip to content

Other class is not mocked as required #747

Closed

Description

@alisevych

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

Activity

  1. moved this to Todo in UTBot Javaon Aug 19, 2022
  2. added this to the Release preparation milestone on Sep 7, 2022
  3. CaelmBleidd commented on Sep 14, 2022

    @CaelmBleidd
    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
  4. removed this from the Release preparation milestone on Sep 28, 2022
  5. added
    spec-release-tailingsFailed to include in the current release, let's include it in the next one
    on Sep 29, 2022
  6. added this to the 2022.12 Release milestone on Oct 7, 2022
  7. Repository owner moved this from Todo to Done in UTBot Javaon Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ctg-bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next one

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions