1 Reply Latest reply: May 20, 2009 9:12 AM by 843789 RSS

    Testing scanner input using output from another class

    843789
      Hi. I have a program that takes command line arguments using scanner and does operations on them. That is all the program does. I would like to automate the testing process by having another class in the program, and upon typing "test" into the console, I'd like the test class to run, and output data not to the screen but to the scanner input in the main program.
      Can anyone suggest something? Or perhaps an easier automated testing process?
      Thanks
      Sutasman
        • 1. Re: Testing scanner input using output from another class
          843789
          Sutasman wrote:
          Hi. I have a program that takes command line arguments using scanner and does operations on them.
          Command line arguments or input?

          Because getting command line arguments using Scanner would be strange.

          Do you run "java -jar myapp.jar -foo" or do you run "java -jar myapp.jar" and then enter stuff?

          The first is using command line arguments, the second one is reading the Standard input.
          That is all the program does. I would like to automate the testing process by having another class in the program, and upon typing "test" into the console, I'd like the test class to run, and output data not to the screen but to the scanner input in the main program.
          Extract the part that interacts with the standard input into its own class that takes an InputStream (or a Reader) as an argument of the constructor.

          For normal operation pass in System.in, for testing pass in a InputStream (or Reader) containing the data you want to use for testing.
          Can anyone suggest something? Or perhaps an easier automated testing process?
          Use JUnit and skip the entire user interface in testing (even if it's just text).