How do you test your code chef applications?

How do you test your applications when you expect input from a Buffer?
Lets say you expect input in the form:
Input:
7
1
51
966369
7
9
999996
11
Do you create a file that you read from or you hardcode the values in the code that you test with.

I am looking for a way to optimize the proccess of testing during development because trial and error is too tedious.

Two approaches that seem to work for me:

  • Small/easy problems: I/O from the console. Few random test cases, plus boundary tests.
  • Long/Medium problems: Make an input file, and an expected output file. A small stub code checks output of my solution with the output file. Allows me to write several test cases, and check the success/failure of each test case. While submitting, comment out the call to the stub.

For the second approach, a very small change of code is required.

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

becomes

String file_path = "./test_cases.txt"; 
BufferedReader br = new BufferedReader(new FileReader(file_path));
//