3

I am trying to accept manual keyboard input while running a JUnit test. However I'm getting the following error:

java.util.NoSuchElementException: No line found

The snippet I'm using is very basic:

Scanner keyboard = new Scanner( System.in ); String userInput = keyboard.nextLine();

It seems JUnit is blocking any user input. I know that normally one wouldn't want keyboard entry during a JUnit test, but I'd like to do so because of the way the environment's set up. My goal is simply to pause the test until I manually say I'm ready for it to continue.

So my question is, how can I do this?

  • You have read this post: http://stackoverflow.com/questions/6415728/junit-testing-with-simulated-user-input – Patrick Feb 26 '14 at 22:32
  • 1
    Yes, I have read that. Unfortunately I do not want to simply hardcode a string, as suggested in that post. My plight is to pause the test until I'm ready to continue. – user2155320 Feb 26 '14 at 22:40
  • A coworker suggested this earlier as well, but I was running the build from a command-line. I found out how to run my stuff in Eclipse again, so I'm going with the breakpoints. It would still be useful to know why JUnit doesn't allow keyboard input, and how to work around that, but my specific problem is solved. Thanks – user2155320 Feb 27 '14 at 23:37

0 Answers0