0
public static void takeAnswers(int answerNumber){
        if(answerNumber<0){
            throw new IllegalStateException();
        }
        Scanner answer = new Scanner(System.in);
        testResponse = answer.next().charAt(0);
        while(!(validateAnswer(testResponse, answerNumber))){
            Question.inValidInput();
        }
    }

so i making this quiz in java and i am just stuck on the junit testing.

"Also, How are we suppose to test for nested methods?

Can we alter the value of a local variable (declared inside the method itself), since it's using scanner and thus waits for a user input and therefore the test just waits forever. "

So basically no matter what value I give to the testResponse , the test still waits for the scanner.

and thus the program just waits there forever.

Aryan Arora
  • 143
  • 2
  • 12
  • What do you mean by "nested methods"? In Java you can't declare method within other method. – Pshemo Sep 18 '18 at 16:53
  • BTW you shouldn't create separate Scanners for standard input in method if it can be called more than once. You should have only once Scanner handling System.in and if method need it pass it as its parameter. – Pshemo Sep 18 '18 at 16:55

0 Answers0