This content has been marked as final. Show 1 reply
Sutasman wrote:Command line arguments or input?
Hi. I have a program that takes command line arguments using scanner and does operations on them.
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).