Open
Description
Description
User gets warning about flaky method and mocked test when user code gets values from method outside the package.
To Reproduce
- Install UnitTestBot plugin built from main in IntelliJ IDEA
- Open UTBot project
- Generate tests for
org.utbot.examples.mock.MockStaticMethodExample#useStaticMethod
with option 'Mock everything outside the package' enabled and "Mock static methods" disabled.
Expected behavior
Mock used to emulate Random.nextRandomInt()
call.
No warnings, because that method definition is:
public static int nextRandomInt() {
return 42;
}
Actual behavior
Generated test contains warning about flaky methods, see code below.
@Test
@DisplayName("useStaticMethod: value > 50 : False -> return 0")
public void testUseStaticMethod_ValueLessOrEqual50() {
MockedStatic mockedStatic = null;
try {
mockedStatic = mockStatic(Random.class);
(mockedStatic.when(Random::nextRandomInt)).thenReturn(50);
/* WARNING!!! Automatically used "Mockito static mocking" framework for mocking statics
because execution encountered flaky methods
To change this behaviour edit [Settings -> UtBot -> Force static mocking] */
MockStaticMethodExample mockStaticMethodExample = new MockStaticMethodExample();
int actual = mockStaticMethodExample.useStaticMethod();
assertEquals(0, actual);
} finally {
mockedStatic.close();
}
}
Additional context
Warning disappears when use enables option "Mock static methods".
Even when nextRandomInt()
is not static
behavior is the same - there is warning about flaky method and usage "Mockito static mocking" framework.
Issue is reproducible in previous version of plugin (2023.3).
Metadata
Metadata
Assignees
Type
Projects
Status
Todo