Change type of 'actual' variable #631
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Before, the type of this variable was the same as the return type of executable under test. However, this could lead to undesired reflection usage: if a method returns
A
, but the real type ofactual
variable isB
(subclass ofA
), then we will not be able to access fields that are declared inB
without reflection, because the variable is declared with typeA
. For example, this can happen when we make equality assertions between fields of expected value and an actual result and some of these fields are fromB
, but are not accessible, because typeA
knows nothing about these new fields.Type of Change
How Has This Been Tested?
This change simply fixes unnecessary reflection usage. So, all tests worked before and should work after this change. The difference is that we will be able to avoid using reflection to access fields of variable
actual
.Automated Testing
The difference can be seen on
org.utbot.examples.objects.ObjectWithPrimitivesExample#max
. If you generate tests for this method before this change, then the fieldanotherX
of the variableactual
will be accessed via reflection, whereas after the change a regular field access is used.Checklist: