-
Notifications
You must be signed in to change notification settings - Fork 47
Test generation fails for Optional<T> class in the plugin #226
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
Labels
comp-symbolic-engine
Issue is related to the symbolic execution engine
ctg-bug
Issue is a bug
priority-top-focus
Top priority chosen by dev team
Comments
dtim
added a commit
that referenced
this issue
Jun 24, 2022
Added a check for overridden classes in `shouldMock` to avoid access to engine classes that are not available in the plugin. Implemented more accurate speculative marking of final fields as not null to avoid losing paths involving `Optional.empty()`, to enable NPE checks for final fields in user code, and to avoid generating non-informative NPE tests for final fields in system classes. UtSettings.checkNpeForFinalFields is now set default (false) in `AbstractTestCaseGEneratorTest` and `SummaryTestCaseGeneratorTest`.
6 tasks
dtim
added a commit
that referenced
this issue
Jun 27, 2022
Added a check for overridden classes in `shouldMock` to avoid access to engine classes that are not available in the plugin. Implemented more accurate speculative marking of final fields as not null to avoid losing paths involving `Optional.empty()`, to enable NPE checks for final fields in user code, and to avoid generating non-informative NPE tests for final fields in system classes. UtSettings.checkNpeForFinalFields is now set default (false) in `AbstractTestCaseGEneratorTest` and `SummaryTestCaseGeneratorTest`.
dtim
added a commit
that referenced
this issue
Jun 27, 2022
Added a check for overridden classes in `shouldMock` to avoid access to engine classes that are not available in the plugin. Implemented more accurate speculative marking of final fields as not null to avoid losing paths involving `Optional.empty()`, to enable NPE checks for final fields in user code, and to avoid generating non-informative NPE tests for final fields in system classes. UtSettings.checkNpeForFinalFields is now set default (false) in `AbstractTestCaseGEneratorTest` and `SummaryTestCaseGeneratorTest`.
dtim
added a commit
that referenced
this issue
Jun 28, 2022
Added a check for overridden classes in `shouldMock` to avoid access to engine classes that are not available in the plugin. Implemented more accurate speculative marking of final fields as not null to avoid losing paths involving `Optional.empty()`, to enable NPE checks for final fields in user code, and to avoid generating non-informative NPE tests for final fields in system classes. UtSettings.checkNpeForFinalFields is now set default (false) in `AbstractTestCaseGEneratorTest` and `SummaryTestCaseGeneratorTest`.
dtim
added a commit
that referenced
this issue
Jun 28, 2022
Added a check for overridden classes in `shouldMock` to avoid access to engine classes that are not available in the plugin. Implemented more accurate speculative marking of final fields as not null to avoid losing paths involving `Optional.empty()`, to enable NPE checks for final fields in user code, and to avoid generating non-informative NPE tests for final fields in system classes. UtSettings.checkNpeForFinalFields is now set default (false) in `AbstractTestCaseGEneratorTest` and `SummaryTestCaseGeneratorTest`.
dtim
added a commit
that referenced
this issue
Jun 28, 2022
Added a check for overridden classes in `shouldMock` to avoid access to engine classes that are not available in the plugin. Implemented more accurate speculative marking of final fields as not null to avoid losing paths involving `Optional.empty()`, to enable NPE checks for final fields in user code, and to avoid generating non-informative NPE tests for final fields in system classes. UtSettings.checkNpeForFinalFields is now set default (false) in `AbstractTestCaseGEneratorTest` and `SummaryTestCaseGeneratorTest`.
dtim
added a commit
that referenced
this issue
Jun 28, 2022
Added a check for overridden classes in `shouldMock` to avoid access to engine classes that are not available in the plugin. Implemented more accurate speculative marking of final fields as not null to avoid losing paths involving `Optional.empty()`, to enable NPE checks for final fields in user code, and to avoid generating non-informative NPE tests for final fields in system classes. UtSettings.checkNpeForFinalFields is now set default (false) in `AbstractTestCaseGEneratorTest` and `SummaryTestCaseGeneratorTest`.
dtim
added a commit
that referenced
this issue
Jun 28, 2022
Added a check for overridden classes in `shouldMock` to avoid access to engine classes that are not available in the plugin. Implemented more accurate speculative marking of final fields as not null to avoid losing paths involving `Optional.empty()`, to enable NPE checks for final fields in user code, and to avoid generating non-informative NPE tests for final fields in system classes. UtSettings.checkNpeForFinalFields is now set default (false) in `AbstractTestCaseGEneratorTest` and `SummaryTestCaseGeneratorTest`.
Repository owner
moved this from In Progress
to Done
in UTBot Java
Jun 28, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
comp-symbolic-engine
Issue is related to the symbolic execution engine
ctg-bug
Issue is a bug
priority-top-focus
Top priority chosen by dev team
Description
No test cases are generated for methods involving Java
Optional<T>
class.UtError
s are generated by the engine duringtraverse
due toClassNotFound
exception:UtOptional
class can't be loaded. This behavior may be reproduced using the Idea plugin, but models are successfully generated for the same code in the engine unit tests.To Reproduce
Generate unit tests for the sample method:
Expected behavior
Two tests are generated, one for each branch in the code (see Additional context for more details).
Actual behavior
Errors are reported:
Environment
Mockito: any configuration. Test framework: JUnit5.
Additional context
The primary error reason:
UtOptional
wrapper is used instead ofOptional
, but the class loader used by the test generator in the plugin can't find it. It's OK (engine-specific wrappers should never leak to the user), butshouldMock
function checks the class and fails withClassNotFound
exception.Adding a check to
shouldMock
fixes the exception, but the execution path corresponding toOptional.empty()
return value is lost unlesscheckNpeForFinalFields
setting is set totrue
(it isfalse
by default). SeeSootField.shouldBeNotNull()
declared inExtensions.kt
.A similar code sample that uses
OptionalInt
instead ofOptional<Integer>
is processed without any problems, because primitive field types are never mocked so no class check is performed.Code sample:
Generated tests:
The text was updated successfully, but these errors were encountered: