Skip to content

Controller's method with @PreAuthorize generates infinitely many same tests. #2727

Open
@ancavar

Description

@ancavar

To Reproduce
Generate integration tests for controller's method which has @PreAuthorize, e.g.

    @GetMapping("/demo")
    @PreAuthorize("hasAuthority('write')")
    public String demo() {
        return "demo";
    }

Expected behavior

Probably shouldn't have this test since it tests nothing.

Actual behavior

  ///region FUZZER: ERROR SUITE for method demo()
    /// Actual number of generated tests (4964) exceeds per-method limit (50)
    /// The limit can be configured in '{HOME_DIR}/.utbot/settings.properties' with 'maxTestsPerMethod' property

    /**
     * @utbot.classUnderTest {@link NameController}
     * @utbot.methodUnderTest {@link NameController#demo()}
     */
    @Test
    @DisplayName("demo:  -> throw AccessDeniedException")
    public void testDemoThrowsADE() {
        /* This test fails because method [com.laurentiuspilca.ssia.controllers.NameController.demo] produces [org.springframework.security.access.AccessDeniedException: Access is denied] */
        nameController.demo();
    }

    /**
     * @utbot.classUnderTest {@link NameController}
     * @utbot.methodUnderTest {@link NameController#demo()}
     */
    @Test
    @DisplayName("demo:  -> throw AccessDeniedException")
    public void testDemoThrowsADE1() {
        /* This test fails because method [com.laurentiuspilca.ssia.controllers.NameController.demo] produces [org.springframework.security.access.AccessDeniedException: Access is denied] */
        nameController.demo();
    }

    /**
     * @utbot.classUnderTest {@link NameController}
     * @utbot.methodUnderTest {@link NameController#demo()}
     */
    @Test
    @DisplayName("demo:  -> throw AccessDeniedException")
    public void testDemoThrowsADE2() {
        /* This test fails because method [com.laurentiuspilca.ssia.controllers.NameController.demo] produces [org.springframework.security.access.AccessDeniedException: Access is denied] */
        nameController.demo();
    }
    
    // and so on

Activity

changed the title [-]Controller's method with `@PreAuthorize` generates infinitely many same tests[/-] [+]Controller's method with `@PreAuthorize` generates infinitely many same tests.[/+] on Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ctg-bugIssue is a bug

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ancavar

        Issue actions

          Controller's method with `@PreAuthorize` generates infinitely many same tests. · Issue #2727 · UnitTestBot/UTBotJava