vendredi 2 décembre 2016

Java: How to AUTOMATICALLY test a console application that gets input from user

I'm writing a console application in Java that gets input from the user by 'Scanner' class. I don't want to enter each time that I test my program the input manually in the console, so I want to put all my inputs in a text file and make the Java program read this text file instead of typing again the inputs.

The way I found to do it is changing the line:

Scanner sc = new Scanner(System.in);

to:

Scanner sc = new Scanner(new File(path_to_text_file));

Can you recommend another way that doesn't involve changing the code?

Aucun commentaire:

Enregistrer un commentaire