Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Fahimah Khan   on May 23 In Java Category.

  
Question Answered By: Elisabeth Bell   on May 23

> Well, I don't understand it yet.
> What do you mean by "hijack a programs input  and output ". Can you
> give me a sample code??

I mean that you can overwrite the standard input and output streams to
be read and write from another source ... such as your java  program.

You can use ByteArrayInputStream and ByteArrayOutputStream to do so.

I would love to give you a code example of how to do this in a really
basic way, but I am working 16 hour days at the moment :( ... Maybe
tomorrow (after my deadline).

> Hope my first question clear enough. Anyway,
> i think my project  will use only character UI, not a complex  GUI. And
> these are the detailed steps :
> 1. Suppose the Homework program  has a function : int calculate(int x,
> int y), which returns x * y. This is the function that must be tested
> at runtime. The students must submit the Homework.java file

Command Line Interfaces are by far the easier ones to do. GUI isn't easy
in any way shape or form. That being said, testing a few dozen CLI
programs submitted by students is going to be a huge headach. I have
seen students that get 97% on assignments fail almost every single test
for really bizzare reasons.

If you need to test  a method that is fixed for every students program,
you could use a script with Unit testing. I don't know what the link is
for c++ unit testing, but JUnit for Java is easy to find and does
exactly that.

> 2. So how should my program works?? I guess my program must try to
> compile Homework.java from each student (guess I can use this by
> executing javac from Runtime). If Homework.class can created, then go
> to step 3. Otherwise, Homework program failed.

This is a simple, simple  script. Heck you could get ANT to go from
directory to directory compiling and then running the tests. Check out
ANT from Apache.

> 3. My project then execute the Homework.class. Well, now
> Homework.class is running. And this is the most confusing part. How
> can i enter first input (for x), second input (for y) and gets the
> output from "calculate" function from the running program?? If this
> part you called as "hijack", how can i interrupt a running program??


So there are a couple of tests types you can do.

The test you seem to be talking about at the moment is a Unit test from
a pre-determined function. Which is pretty simple to do (use ANT and
JUnut for Java (shouldn't take too long).

I also think that you where infering that you should test the overall
input and output of the application. Such as if you made a program that
accepted comands and then responded to them, your program would capture
the standard in and out streams and then read and write to them at will.


>
> Hope someone can help  me, cause this is really important to
> me.........
>

To do the simple version of what you want isn't that hard ... but like
Dave said in an earlier project, to make the real deal is probably out
the realms of any one programmer.

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on test a program? Or get search suggestion and latest updates.


Tagged: