GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Other class is not mocked as required · Issue #747 · UnitTestBot/UTBotJava

Other class is not mocked as required #747

New issue
Copy link
New issue
Copy link
Closed
#1033
Closed
Other class is not mocked as required#747
#1033
Copy link
Assignees
Markoutte
Labels
ctg-bugIssue is a bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next oneFailed to include in the current release, let's include it in the next one
Milestone
2022.11 Release

Description

@alisevych
alisevych
opened on Aug 19, 2022
Issue body actions

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. korifey
    added this to UTBot Javaon Aug 19, 2022
  2. korifey
    moved this to Todo in UTBot Javaon Aug 19, 2022
  3. alisevych
    added
    ctg-bugIssue is a bugIssue is a bug
    on Aug 19, 2022
  4. alisevych
    assigned
    CaelmBleidd
    on Aug 19, 2022
  5. alisevych
    added this to the Release preparation milestone on Sep 7, 2022
  6. CaelmBleidd commented on Sep 14, 2022

    @CaelmBleidd
    CaelmBleidd
    on Sep 14, 2022
    Member
    More actions

    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
    Reacted by Alena Lisevych
  7. CaelmBleidd
    assigned
    Markoutte
    and unassigned
    CaelmBleidd
    on Sep 14, 2022
  8. alisevych
    removed this from the Release preparation milestone on Sep 28, 2022
  9. Markoutte
    added a commit that references this issue on Sep 29, 2022

    Other class is not mocked as required #747

    7a7eeb8
  10. alisevych
    added
    spec-release-tailingsFailed to include in the current release, let's include it in the next oneFailed to include in the current release, let's include it in the next one
    on Sep 29, 2022
  11. Markoutte
    added a commit that references this issue on Oct 4, 2022

    Other class is not mocked as required #747

    35408f2
  12. alisevych
    added this to the 2022.12 Release milestone on Oct 7, 2022
  13. Markoutte
    added 2 commits that reference this issue on Oct 11, 2022

    Other class is not mocked as required #747

    14f4b94

    Other class is not mocked as required #747 (#1033)

    1ba00d4
  14. Markoutte
    closed this as completedin #1033on Oct 11, 2022
  15. Repository owner moved this from Todo to Done in UTBot Javaon Oct 11, 2022
  16. AbdullinAM
    added 2 commits that reference this issue on Oct 17, 2022

    Other class is not mocked as required UnitTestBot#747 (UnitTestBot#1033)

    341a917

    Other class is not mocked as required UnitTestBot#747 (UnitTestBot#1033)

    1a18c53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Markoutte
    Markoutte

Labels

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

Type

No type

Projects

  • UTBot Java
    Status
    Done
    Show more project fields

Milestone

  • 2022.11 Release

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.