-
Notifications
You must be signed in to change notification settings - Fork 47
Improve detection of NPEs caused by this instance fields being null in Spring unit tests #2617
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
Conversation
… of `java.lang.Object`s
} | ||
|
||
// a method for testing the case when the Engine produces two models on @Autowired variables of the same type | ||
public Boolean checker() { | ||
return personOne.getName().equals("k") && personTwo.getName().length() > 5 && baseOrders.isEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: this was not a sufficient condition to guarantee that personOne != personTwo
, since engine could have just created one personMock
and configure it like this: when(personMock.getName()).thenReturn("k", "123456")
, so this test was updated. Discussed changes with original author @tepa46 and added him to reviewers.
Description
Fixes #2589 (desired NPE test is generated by fuzzer, because symbolic engine has troubles dealing with
getClass() == o.getClass()
condition.To make fuzzer able to generate
Object
of typeOrder
specialJavaLangObjectValueProvider
was added that tries to useclassUnderTest
wheneverjava.lang.Object
is needed (plainnew Object()
can still be used wherejava.lang.Object
is needed).In case class under test has some hard to pass validation inside of the constructor and fuzzer is asked to create multiple
java.lang.Object
s,RemovingConstructFailsUtExecutionInstrumentation
was used in all Spring tests (in short, it detects impossible to create due to exceptions thrown by constructor models instateBefore
and replaces them withUtNullModel
s, making it easier for fuzzer to find "creatable" input and actually call method under test).Finally,
InjectMocksValueProvider
was made to respectNonNullSpeculator
(previously fuzzer considered all fields to be non-null
).How to test
Manual tests
NPE unit be generated by fuzzer for
Order.equals()
fromspring-boot-testing
project.Generate unit tests for the following classes individually with fuzzer only and with engine only, each of them should generate NPE tests for methods marked with "NPE expected" and no NPE tests for methods marked with "no NPE expected".
Self-check list