Description
Description
The Concrete Executor works incorrectly with mocked fields in <init>
of classes different from the CUT. For example, consider the following code:
class ClassWithRandomField {
public Random random = new Random();
public int nextInt() {
return random.nextInt();
}
}
public class ClassUsingClassWithRandomField {
public int useClassWithRandomField() {
ClassWithRandomField classWithRandomField = new ClassWithRandomField();
return classWithRandomField.nextInt();
}
}
When generating tests for the ClassUsingClassWithRandomField#useClassWithRandomField
method (with no mocking strategy but with java.util.Random
included to mockAlways
classes), the symbolic engine mocks constructors of the java.util.Random
class and its method nextInt
. So, the value returned from the MUT should equal the value returned by the mocked method nextInt
. But in the concrete execution the random
field becomes not mocked, which leads to using the real nextInt
method and a diversion with the symbolic engine, and, as a result, an incorrect test.
To Reproduce
- Run generating tests action for the method
useClassWithRandomField
withno mocks
strategy but withjava.util.Random
included tomockAlways
classes - Run a generated test.
Expected behavior
Generated test always passes.
Actual behavior
Almost always (sometimes the real nextInt
value may return the same value as what is supposed to be mocked) generated test fails.
Environment
No extra environment.
Additional context
No additional context.
Metadata
Metadata
Assignees
Type
Projects
Status