System.in
and System.out
) it is
almost impossible to verify the output "by eye". Instead, one should
redirect input and output, and then use a diff utility (like diff, Meld,
or Kdiff3).
For example, suppose the application is
named Calculator
, the input file is
named test.in
(for "input"), and you wan the output
file to be named test.act
(for "actual"). From the
command line you would enter:
java Calculator < test.in > test.out
The classic command-line utility that provides this functionality is
diff
, however there many GUI tools that also provide this
functionality (e.g., Meld and Kdiff3).
Continuing with the example above, suppose the expected output file is
named test.exp
(for "expected"), then you can compare the
two using diff as follows:
diff test.exp test.act
(You can do the same thing using Meld and Kdiff3, or you can load the files from the GUI.)
Copyright 2019