mercredi 22 juin 2016

How to unit-test function that uses global variable?

Suppose you have a class

class NeedToTestThisClass{
    private String string1;
    ....
    ....

    private void needToTestThisMethod(){
        if(string1.equals("a")){
            ...
        }
        else{
            ....
            }
   }
}

How can I test this method with different string values? The string has no setter, and not included in the constructor. I cannot change the code. I have powermock. The question is easy, but can't figure out the way. thanks.

Aucun commentaire:

Enregistrer un commentaire