vendredi 29 juillet 2016

How to unit test method with if else and no return conditions

I have a method with following code:

public void myMethod() {
    if (condition1) {
        doSomething1();
        if (condition2) {
            doSomething2();
        } else {
            doSomething3();
        }
    }
 }

Now doSomething1, doSomething2, doSomething3 are void methods. How to unit-test myMethod ? eg: if condition1 is satisfied check if doSomething1 was called.

Is there something we can do to refactor this to make easily testable ?

Aucun commentaire:

Enregistrer un commentaire