It is a mistake to test how you describe. And denotes a poor code structure and is a definite smell of code , you must reorganize and unit test this code. Given that you are trying to verify that it was not called, it should also be that you also want to pass the test when it was called.
You must have one method, so for more reasonable unit testing, you can output the logic after returning, enclosing it in a method, and unit test the output of this method.
A unit test , , , /, .
, , , unit test. , , , return , , .