Skip to content

No tests are generated for methods in enums with nested anonymous classes #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dtim opened this issue Jul 30, 2022 · 1 comment
Closed
Assignees
Labels
comp-codegen Issue is related to code generator comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one

Comments

@dtim
Copy link
Collaborator

dtim commented Jul 30, 2022

Description

No tests can't be generated by the symbolic engine for methods in enum classes whose values have corresponding anonymous classes.

Note: I am not currently sure that there are no cases where tests would be generated, this question has to be investigated. See #300 for a sample configuration for the contest estimator that will be useful for collecting data.

To Reproduce

Generate the test suite for the State.findStateByCode() method in the following code.

public enum State {
    OPEN(255) {
        @Override
        public String toString() {
            return "<open>";
        }
    },
    CLOSED(127) {
        @Override
        public String toString() {
            return "<closed>";
        }
    },
    UNKNOWN(0) {
        @Override
        public String toString() {
            return "<unknown>";
        }
    };

    private final int code;

    State(int code) {
        this.code = code;
    }
    
    public int getCode() {
        return code;
    }

    public static State findStateByCode(int code) {
        for (State state: values()) {
            if (state.getCode() == code) {
                return state;
            }
        }
        return UNKNOWN;
    }
}

Expected behavior

A non-empty test suite should be generated, no errors should be reported.

Actual behavior

No tests are generated, the error message is displayed: "UtBot failed to generate any test cases for class State".

Environment

This behavior does not depend on the specific test framework configuration and mocking settings. It can be reproduced in both Java 8 and Java 11, as well as on fuzzer settings.

Additional context

Enum constructor does not prevent test generation, anonymous nested classes do.

The issue is probably related to the limited support of anonymous classes in the code generator. It may be reproduced even with fuzzing turned on, and even with fuzzing only, so it seems that it is a codegen error. At the same time, anonymous class processing in the symbolic engine should be checked too.

@dtim dtim added ctg-bug Issue is a bug comp-codegen Issue is related to code generator comp-symbolic-engine Issue is related to the symbolic execution engine labels Jul 30, 2022
@dtim dtim self-assigned this Jul 30, 2022
@korifey korifey moved this to Todo in UTBot Java Jul 30, 2022
@ArsenHD ArsenHD mentioned this issue Aug 22, 2022
7 tasks
@alisevych alisevych added this to the Release preparation milestone Sep 7, 2022
@denis-fokin denis-fokin added the spec-release-tailings Failed to include in the current release, let's include it in the next one label Sep 28, 2022
@denis-fokin denis-fokin removed this from the Release preparation milestone Sep 28, 2022
@alisevych alisevych added this to the 2022.12 Release milestone Oct 7, 2022
@alisevych alisevych assigned CaelmBleidd and unassigned dtim Nov 29, 2022
@alisevych alisevych removed this from the 2022.12 Release milestone Dec 2, 2022
@CaelmBleidd
Copy link
Member

Currently, it works fine
image

@github-project-automation github-project-automation bot moved this from Todo to Done in UTBot Java Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one
Projects
Archived in project
Development

No branches or pull requests

4 participants