samedi 28 décembre 2019

JUNIT TEST FOR VOID METHOD ( output-input dependency )

I came up with a problem while trying to write a JUnit test for one specific method. I searched for possible solutions but many of them were not helpful as the output was not dependent on the input. Any help would be much appreciated.

My class method looks like this:

public static void method1() {
    Scanner input = new Scanner(System.in);
    String state = input.nextLine();
    if( /* condition dependent on state value */ ) {
        System.out.println("...");
    }
    else {
        System.out.println("..."+state+"...");
}

How to write a JUnit test for it, can Robot class somehow solve the problem?

Aucun commentaire:

Enregistrer un commentaire