title: JUnit testing with simulated user input
body: <p>I am trying to create some JUnit tests for a method that requires user input. The method under test looks somewhat like the following method:</p>
  
  <pre><code>public static int testUserInput() {
      Scanner keyboard = new Scanner(System.in);
      System.out.println("Give a number between 1 and 10");
      int input = keyboard.nextInt();
  
      while (input &lt; 1 || input &gt; 10) {
          System.out.println("Wrong number, try again.");
          input = keyboard.nextInt();
      }
  
      return input;
  }
  </code></pre>
  
  <p>Is there a possible way to automatically pass the program an int instead of me or someone else doing this manually in the JUnit test method? Like simulating the user input? </p>
  
  <p>Thanks in advance.</p>