How to check void method if condition is met

How to check it?

public void TestMethod()
{
   if(aDenpendency.someMethod()) return;

   // Followed by other logic....
}

I have no other dependency in the following logic, so I could not use AssertWasNotCalled.

Thanks in advance!

+3
source share
2 answers

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 , , .

+4

, , , "", , - Running\Processing\Aborted ..?

, void , , . ;

if(condition){
    _status = 1; //Or use an enumeration would be better
    return;
}

Accessor.

, , , void Process(). , , (, , ), , , - , -, ( , , )

, , , .

0

All Articles