• Post Reply Bookmark Topic Watch Topic
  • New Topic

Batch command things! Help!  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

I have a program that takes a load of inputs continuously from the command line, each seperated by hitting return. So basically, I execute the program, it asks for input at the cmd line, you type, you hit enter, it asks for more input, you type, you hit enter etc.
A typical command sequence would be:
10
S
11
SW
20
E
etc...

Now the problem is, is that I'm speding aaages typing these in in order to test for errors. I've created a batch file which reads


But all it does is run the program, and wait for the first line of input at the command line. How can I get it to put in the correct values automatically?

Please help, you would save me a whole lot of time if you do!

Thanks buddies

Mike
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

the solution is quite easy: Separate layers. Create a function
that takes a String as an argument - that would be the input line,
and outputs the "whatever-it-is" your program writes out as output.
Then, write a function that reads lines from stdio, sends them
to the function and prints out the returned value.

Now, don't write any batch files for testing. Just implement a
function test (or as many such functions as you need) which will
just call your function that takes the line and returns "whatever-it-is".

Was that clear?

When you are finished with that you might check out the package
called JUnit and also a forum testing here on JavaRanch.

Petr
 
Mike Smike
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks buddy, I'll give that a try!



Mike
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into the basic DOS redirect. This should read stdin from a file of input commands:

java myProgram < input.txt

You can also design your program for testability. I think that's what Petr was after;

I have a lot of testers that look like this. the "main" is a common structure establishing input & expected results. The runTest has to be custom for the thing I'm testing.

As you add new features to your program it's neat to write the tests before you write the code to make them work. That makes you think very clearly about input & expected results. If you want to get into this mode of writing (recommended!) see JUnit.org.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!