Skip to content

Parametrized test with contradictory asserts: assertNotNull and assertNull #2390

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

Open
tyuldashev opened this issue Jul 10, 2023 · 0 comments
Assignees
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug

Comments

@tyuldashev
Copy link
Collaborator

Description
When generating parametrized test for Graph class there are two opposite asserts appears in one of the tests: assertNotNull and assertNull.

To Reproduce

Steps to reproduce the behavior:

  1. Open the 'UTBot Java' project in IntelliJ Idea
  2. Use plugin to generate parametrized tests for org.utbot.examples.algorithms.Graph#getAdj. No matter if it's JUnit5 or TestNG.
  3. Open the generated test

Expected behavior
Generated test would looks something like that. One assert type in each if/else branch

    @ParameterizedTest
    @MethodSource("org.utbot.examples.algorithms.GraphTest#provideDataForGetAdj")
    public void parameterizedTestsForGetAdj(Graph graph, int[][] expectedResult) {
        int[][] actual = graph.getAdj();

        if (expectedResult == null) {
            assertNull(actual);
        } else {
            assertNotNull(actual);
        }
    }

Actual behavior
Please note that else branch contains two opposite assertions.

    @ParameterizedTest
    @MethodSource("org.utbot.examples.algorithms.GraphTest#provideDataForGetAdj")
    public void parameterizedTestsForGetAdj(Graph graph, int[][] expectedResult) {
        int[][] actual = graph.getAdj();

        if (expectedResult == null) {
            assertNull(actual);
        } else {
            assertNotNull(actual);
            assertNull(actual);
        }
    }

Additional context

The problem is pre-existing, it also exists in 2022.2.5.

@tyuldashev tyuldashev added ctg-bug Issue is a bug comp-codegen Issue is related to code generator labels Jul 10, 2023
@alisevych alisevych added this to the Upcoming Release milestone Jul 10, 2023
@alisevych alisevych removed this from the October Release milestone Oct 2, 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 ctg-bug Issue is a bug
Projects
Status: Todo
Development

No branches or pull requests

3 participants