Skip to content
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

Public constructor is ignored in tests generated by Fuzzer #2539

Closed
alisevych opened this issue Aug 21, 2023 · 0 comments · Fixed by #2544
Closed

Public constructor is ignored in tests generated by Fuzzer #2539

alisevych opened this issue Aug 21, 2023 · 0 comments · Fixed by #2544
Assignees
Labels
comp-codegen Issue is related to code generator comp-fuzzing Issue is related to the fuzzing comp-spring Issue is related to Spring projects support ctg-bug Issue is a bug

Comments

@alisevych
Copy link
Member

alisevych commented Aug 21, 2023

Description

Public constructor is ignored in tests generated by Fuzzer.

To Reproduce

  1. Install plugin built from main in IntelliJ IDEA
  2. Open spring-petclinic project
  3. Copy Recursion Java class from utbot-sample
  4. Paste it into org/springframework/samples/petclinic/model in spring-petclinic
  5. Set Fuzzing 100% in File -> Settings -> Tools -> UnitTestBot
  6. Generate tests for Recursion$factorial

Expected behavior

Recursion class is public and should be instantiated without reflection, just with new T()

Actual behavior

UtUtils.createInstance method is used to instantiate Recursion in all Fuzzing generated tests.

Screenshots, logs

	///region FUZZER: SUCCESSFUL EXECUTIONS for method factorial(int)

	/**
	 * @utbot.classUnderTest {@link Recursion}
	 * @utbot.methodUnderTest {@link Recursion#factorial(int)}
	 */
	@Test
	@DisplayName("factorial: n = positive (mutated from -2147483647) -> return 1")
	public void testFactorialReturnsOne() throws Exception {
		Recursion recursion = ((Recursion) createInstance("org.springframework.samples.petclinic.model.Recursion"));

		int actual = recursion.factorial(1);

		assertEquals(1, actual);
	}

Environment

IntelliJ IDEA version - Ultimate 2023.2
Project - spring-petclinic
JDK - 17

Additional context

If symbolic execution is on, tests generated with symbolic engine have correct instantiation with direct constructor call:

    ///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method factorial(int)

    /**
     * @utbot.classUnderTest {@link Recursion}
     * @utbot.methodUnderTest {@link Recursion#factorial(int)}
     * @utbot.executesCondition {@code (n == 0): False}
     * @utbot.invokes {@link Recursion#factorial(int)}
     * @utbot.triggersRecursion factorial, where the test return from: {@code return 1;}
     * @utbot.returnsFrom {@code return n * factorial(n - 1);}
     */
    @Test
    @DisplayName("factorial: -> return 1")
    public void testFactorial_NNotEqualsZero() {
        Recursion recursion = new Recursion();

        int actual = recursion.factorial(1);

        assertEquals(1, actual);
    }
@alisevych alisevych added ctg-bug Issue is a bug comp-codegen Issue is related to code generator comp-fuzzing Issue is related to the fuzzing comp-spring Issue is related to Spring projects support labels Aug 21, 2023
@alisevych alisevych added this to the Spring Phase 4 milestone Aug 21, 2023
@EgorkaKulikov EgorkaKulikov linked a pull request Aug 22, 2023 that will close this issue
6 tasks
@github-project-automation github-project-automation bot moved this from Todo to Done in UTBot Java Aug 23, 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-fuzzing Issue is related to the fuzzing comp-spring Issue is related to Spring projects support ctg-bug Issue is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants