-
Notifications
You must be signed in to change notification settings - Fork 38
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
Ease troubleshooting of unit tests with calls to mock unstubbed methods #350
Comments
Actually, mockito provides smart nulls which supports the
It may be less strict than a custom Answer systematically throwing an exception, as it attempts to return first tries to return ordinary values for "empty" objects, thereby possibly still hiding some unstubbed methods See https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Mockito.html#RETURNS_SMART_NULLS
Here is a sample of such exception thrown with line navigation provided by intellij See refined attempt at orange-cloudfoundry/osb-cmdb@bb8d5e9 The full exception is at https://gist.github.com/gberche-orange/0e113d844c454f6f2579d8e0f2645f26 To apply smart nulls to all app broker tests requires converting tests using BDDMockito (in form of As such manual conversion is time consumming, intellij structural search and replace can mostly automate this Here is an export of this search/replace template which can be imported into intellij. If opting for the "use static imports" checkbox, then I'm happy to give it a try on the whole codebase once my outstanding PRs get merged (as to avoid time consumming conflicts handing) |
Is this absolutely necessary? It was an effort to convert everything to BDDMockito. 😅 |
https://stackoverflow.com/a/15835255/1484823 details why BDDMockito can't be used with small nulls
I'm sorry if this feels like going backwards. I hope that friendly exceptions will save plenty of time to app broker maintainers when tests need change, and will outweight the readability benefits of BDDMockito. Hopefully the "intellij structural search and replace" practice should make it easier to apply future similar syntax changes in used libraries. |
|
Currently, unit tests make heavy use of mocks. When mocks are improperly configured, calls to unstubbed methods return null, which is hard to diagnose with async reactor calls.
After adding
Hooks.onOperatorDebug();
stack trace such as the following are displayed, but do not display the actual stubbed method call invocation, to ease comparison with mock setupPossible improvement: systematically throw a exception is friendly message when an unstubbed method call invocation is received:
This is supported through a custom default mockito answer, see https://stackoverflow.com/a/15835255/1484823
I applied this in a sample test in orange-cloudfoundry/osb-cmdb@b2324e4#diff-4a2e062758255b0f47b073e44268b72c as part of #292
The text was updated successfully, but these errors were encountered: