UTBotJava icon indicating copy to clipboard operation
UTBotJava copied to clipboard

Hanging tests duplicates are not minimized

Open alisevych opened this issue 3 years ago • 1 comments

Description

Hanging tests duplicates are not minimized. There are two identical tests: one generated by Fuzzing, one by Symbolic engine (when default or some custom mode is used).

To Reproduce

  1. Open/create a project in IntelliJ Idea
  2. Install one of the latest plugins built from main
  3. In Settings -> Tools -> UnitTestBot set Fuzzing + Symbolic generation mode
  4. Check Hanging test timeout (1000 ms by default)
  5. Generate tests for the following code:
    public void sleep() throws InterruptedException {
        Thread.sleep(5000);
    }

Expected behavior

One test on timeout should be present in the resulting test class.

Actual behavior

There are two identical tests in the test class.

Visual proofs (screenshots, logs, images)

    ///region SYMBOLIC EXECUTION: TIMEOUTS for method sleep()

    /**
     * @utbot.classUnderTest {@link TimeoutTest}
     * @utbot.methodUnderTest {@link TimeoutTest#sleep()}
     * @utbot.invokes {@link Thread#sleep(long)}
     */
    @Test
    @DisplayName("sleep:  -> TimeoutExceeded")
    @org.junit.jupiter.api.Timeout(value = 1000L, unit = TimeUnit.MILLISECONDS)
    public void testSleep_ThreadSleep() throws InterruptedException {
        TimeoutTest timeoutTest = new TimeoutTest();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
        assertTimeoutPreemptively(Duration.ofMillis(1000L), () -> timeoutTest.sleep());
    }
    ///endregion

    ///region FUZZER: TIMEOUTS for method sleep()

    /**
     * @utbot.classUnderTest {@link TimeoutTest}
     * @utbot.methodUnderTest {@link TimeoutTest#sleep()}
     */
    @Test
    @DisplayName("sleep: ")
    @org.junit.jupiter.api.Timeout(value = 1000L, unit = TimeUnit.MILLISECONDS)
    public void testSleep() throws InterruptedException {
        TimeoutTest timeoutTest = new TimeoutTest();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
        assertTimeoutPreemptively(Duration.ofMillis(1000L), () -> timeoutTest.sleep());
    }
    ///endregion

Environment

IntelliJ IDEA 2022.3 / 2023.1

alisevych avatar Apr 11 '23 14:04 alisevych

Another illustration of timed out tests minimization:

  • Generate tests by fuzzer for org.utbot.examples.exceptions.ExceptionExamples#hangForSeconds method
  • There are dozens (~30-40) of similar tests. Some of them completely the same, for instance for corner cases:
    @Test
    @DisplayName("hangForSeconds: seconds = max")
    @org.junit.jupiter.api.Timeout(value = 1000L, unit = TimeUnit.MILLISECONDS)
    public void testHangForSecondsWithCornerCase4() throws InterruptedException {
        ExceptionExamples exceptionExamples = new ExceptionExamples();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
        assertTimeoutPreemptively(Duration.ofMillis(1000L), () -> exceptionExamples.hangForSeconds(Integer.MAX_VALUE));
    }

    @Test
    @DisplayName("hangForSeconds: seconds = max")
    @org.junit.jupiter.api.Timeout(value = 1000L, unit = TimeUnit.MILLISECONDS)
    public void testHangForSecondsWithCornerCase5() throws InterruptedException {
        ExceptionExamples exceptionExamples = new ExceptionExamples();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
        assertTimeoutPreemptively(Duration.ofMillis(1000L), () -> exceptionExamples.hangForSeconds(Integer.MAX_VALUE));
    }

tyuldashev avatar Jul 11 '23 13:07 tyuldashev