Skip to content

Duplicating Kotlin tests are created #1271

Open
@alisevych

Description

@alisevych

Description

Test generation for a Kotlin function produces two identical tests with function call without parameters.

To Reproduce

  1. Install one of the latest builds of UnitTestBot plugin from main into IntelliJ Idea 2022.1.4
  2. Create a project with Kotlin support
  3. Use plugin to generate tests for the following Kotlin class:
const val question = "life, the universe, and everything"
const val answer = 42

public class DefaultArguments {

    val tripleQuotedString = """
    #question = "$question"
    #answer = $answer""".trimMargin("#")

    fun main() {
        println(tripleQuotedString)
    }
}

Expected behavior

Identical tests are supposed to be minimized - in regular cases only one test should be present in the resulting test class.

Actual behavior

Generated Kotlin test contains two identical tests.

Visual proofs (screenshots, logs, images)

The following test class is generated:

public class DefaultArgumentsTest {
    ///region Test suites for executable koans.DefaultArguments.main

    ///region

    /**
     * @utbot.classUnderTest {@link DefaultArguments}
     * @utbot.methodUnderTest {@link DefaultArguments#main()}
     */
    @Test
    @DisplayName("main: arg_0 = DefaultArguments()")
    public void testMain() {
        DefaultArguments defaultArguments = new DefaultArguments();

        defaultArguments.main();
    }
    ///endregion

    ///region FUZZER: SUCCESSFUL EXECUTIONS for method main()

    /**
     * @utbot.classUnderTest {@link DefaultArguments}
     * @utbot.methodUnderTest {@link DefaultArguments#main()}
     */
    @Test
    @DisplayName("main: main: arg_0 = DefaultArguments()")
    public void testMain1() {
        DefaultArguments defaultArguments = new DefaultArguments();

        defaultArguments.main();
    }
    ///endregion

    ///endregion
}

Environment

Windows 10 Pro
IDEA 2022.1.4

Metadata

Metadata

Assignees

Labels

ctg-bugIssue is a buglang-kotlinIssue is related to Kotlin language support

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions