Skip to content

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

Closed
@dtim

Description

@dtim

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.

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorcomp-symbolic-engineIssue is related to the symbolic execution enginectg-bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next one

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions