Skip to content

Summaries are not generated for methods from nested classes of nested classes #710

Closed

Description

@volivan239

Description

If we have a chain of at least three classes nested in each other (like class A { class B { class C { int f(); } } } ), summaries are not generated for the functions of the innermost of them (A.B.C.f() in our example).

To Reproduce

UPD. Nested classes are now supported in plugin, so the behavior can be reproduced just by launching plugin on the below class

As nested classes are currently supported only in contest estimator, the easiest way to reproduce the bug is through tests:

  1. Add file DeepNested.java into utbot-sample/src/main/java/org/utbot/examples/inner/ with the following content:
package org.utbot.examples.inner;

public class DeepNested {
    public class Nested1 {
        public class Nested2 {
            public int f() {
                return 0;
            }
        }
    }
}
  1. Add file DeepNestedTest.kt into utbot-summary-tests/src/test/kotlin/examples/inner/ with the following content:
package examples.inner

import examples.SummaryTestCaseGeneratorTest
import org.junit.jupiter.api.Test
import org.utbot.examples.DoNotCalculate
import org.utbot.examples.inner.DeepNested
import org.utbot.framework.plugin.api.MockStrategyApi

class DeepNestedTest : SummaryTestCaseGeneratorTest(
    DeepNested::class,
) {
    @Test
    fun testF() {
        val summary1 = "Test returns from: return 0;"

        val method = DeepNested.Nested1.Nested2::f
        val mockStrategy = MockStrategyApi.NO_MOCKS
        val coverage = DoNotCalculate

        val summaryKeys = listOf(
            summary1
        )

        summaryCheck(method, mockStrategy, coverage, summaryKeys)
    }
}

Expected behavior

Test passes, as corresponding summaries are generated for tests for A.B.C.f()

Actual behavior

Test fails because no summaries are generated.

Visual proofs (screenshots, logs, images)

Test fails with assertion message

The following comments were produced by the UTBot, but were not found in the list of comments passed in the check() method:

-------------------------------------------------------------

null-------------------------------------------------------------


The following comments were passed in the check() method, but were not found in the list of comments produced by the UTBot:

-------------------------------------------------------------

Test returns from: return 0;
-------------------------------------------------------------

Environment

Nothing specific.

Additional context

For me it seems that problem is in org.utbot.summary.ast.SourceCodeParser#traverseInnerClassDeclarations and the fact that it doesn't make any recursive calls.

Activity

  1. moved this to Todo in UTBot Javaon Aug 11, 2022
  2. added
    ctg-bugIssue is a bug
    comp-summariesSomething related to the method names, code comments and display names generation
    on Aug 11, 2022
  3. amandelpie commented on Aug 17, 2022

    @amandelpie
    Collaborator

    @volivan239 could you please notify me, when nested class will be supported not only in the ContestEstimator

  4. volivan239 commented on Aug 17, 2022

    @volivan239
    CollaboratorAuthor

    @volivan239 could you please notify me, when nested class will be supported not only in the ContestEstimator

    @amandelpie, OK, that's no problem. Right now test generation for nested classes from plugin works in this branch. I will notify once it will be merged into main, but that's unlikely to happen soon because currently related people are on vacations.

  5. volivan239 commented on Aug 31, 2022

    @volivan239
    CollaboratorAuthor

    @amandelpie nested classes are now supported in plugin. The behavior can be reproduced just by copy-pasting DeepNested class from example to any project and launching plugin on it.

  6. Repository owner moved this from Todo to Done in UTBot Javaon Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

comp-summariesSomething related to the method names, code comments and display names generationctg-bugIssue is a bug

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions