Skip to content

Tests on timeout for JUnit4 and TestNG are generated without method under test call #1933

Closed
@alisevych

Description

@alisevych

Description

Tests on timeout for JUnit4 are generated without method under test call.

To Reproduce

  1. Install one of the latest IU plugin built from main in IntelliJ Idea 2022.2 Ultimate - take utbot-intellij-IU-2023.3.* artefact
  2. Create a project and add the following class:
public class A {

    public int hangForSeconds(int seconds) {
        for (int i = 1; i < seconds; i++) {
            try {
                Thread.sleep(1001);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        return seconds;
    }
}
  1. Generate tests for it
    with JUnit4 / TestNG testing framework selected
    with default settings (Fuzzing/Symbolic) and Mock everything outside package and Mock static methods
  2. Check the generated tests

Expected behavior

Generated test on timeouts should contain call of the method under test.

Actual behavior

JUnit4 test on timeout has comment /* This execution may take longer than the 1000 ms timeout and therefore fail due to exceeding the timeout. */
But there is no method call.

Visual proofs (screenshots, logs, images)

Tests generated with JUnit4 framework:

@Test(timeout = 1000L)
    public void testHangForSeconds_ThreadSleep() {
        A a = new A();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
    }

Tests generated with TestNG framework:

    @Test(description = "hangForSeconds: return seconds -> TimeoutExceeded", timeOut = 1000L)
    public void testHangForSeconds_ThreadSleep() {
        A a = new A();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
    }

Environment

Seems to be environment independent issue.
Used: Windows 10 Pro, Gradle, JDK 8-17

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorcomp-contest-estimatorIssue is related to contest estimatorctg-bugIssue is a buglang-javaIssue is related to Java supportpriority-top-focusTop priority chosen by dev team

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions