You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a test class is using strict stubs and mocking static methods, tests that have extra invocations declared that are not used are not detected as such. They should be detected when strict stubs are being used and the test should fail.
This is due to the location (in the class with the line number) being calculated incorrectly. All static mocks end up having the same location. The strict stub detection puts the invocations into a map keyed by the location and the result is a single entry in the map when there should be one for each "when" for the mock.
This test can be dropped into a powermock working dir and executed. It will pass but should fail. The last two commented lines should be required for it to pass but they are not. The println statements show that the location for each invocation is calculated to be the same (inside the powermock library).
The root cause is the StackTraceCleaner in StackTraceCleanerProvider not removing all the elements in the stack that need to be removed to get to the element that represents the line where the invocation is really declared in the test.
I have made a change to the cleaner and have added a unit test that I will submit as a pull request after creating this issue.
The text was updated successfully, but these errors were encountered:
When a test class is using strict stubs and mocking static methods, tests that have extra invocations declared that are not used are not detected as such. They should be detected when strict stubs are being used and the test should fail.
This is due to the location (in the class with the line number) being calculated incorrectly. All static mocks end up having the same location. The strict stub detection puts the invocations into a map keyed by the location and the result is a single entry in the map when there should be one for each "when" for the mock.
This test shows the behavior:
This test can be dropped into a powermock working dir and executed. It will pass but should fail. The last two commented lines should be required for it to pass but they are not. The println statements show that the location for each invocation is calculated to be the same (inside the powermock library).
The root cause is the StackTraceCleaner in StackTraceCleanerProvider not removing all the elements in the stack that need to be removed to get to the element that represents the line where the invocation is really declared in the test.
I have made a change to the cleaner and have added a unit test that I will submit as a pull request after creating this issue.
The text was updated successfully, but these errors were encountered: