I have a simple Java console application and would like to test its input / output automatically. The input is always only one line, but the output is sometimes more than one line.
How can I do this? (with a Linux shell / Python / Eclipse / Java)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use pipes in Linux. For example, run your problem like this:
This will run myProgram and feed input from input_file. All output will be written to a file called output_file.
Now create another file called expected_file which you should handcreate to specify the exact output you expect on some input (specifically, the input you have in input_file).
Then you can use diff to compare the output_file and the expected_file:
This will output any differences between the two files. If there are no differences, nothing will be returned. Specifically, if something gets returned, your program does not work correctly (or your test is wrong).
The final step is to link all these commands in some scripting language like Ruby (:)) or Bash (:().
This is the most straight-forward way to do this sort of testing. If you need to write more tests, consider using some test frameworks like junit.