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?

3
  • You have read this post: stackoverflow.com/questions/6415728/… Commented Feb 26, 2014 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. Commented Feb 26, 2014 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 Commented Feb 27, 2014 at 23:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.