testing main method using junit

testing main method using junit

Post by Boby Georg » Thu, 14 Feb 2002 10:07:00

Hi all,
    How do i test the main method using Junit?

/*skeleton code*/

public static void main(String[] args) {
    Someclass object = new SomeClass();
     BufferedReader br = new BufferedReader(new InputStream(System.in));
    i = Integer.parseInt.(br.readLine());
    i= 55 * i +24;
j= 5*j + i;
System.out.println("final value of j is " + j);


I want Junit to called my main method, then i input a value which undergoes
computation inside main and other methods and finally i want to check the
value of j.

Thanks for your efforts!


testing main method using junit

Post by Kelly Morriso » Fri, 15 Feb 2002 05:43:38

Quote:> Hi all,
>     How do i test the main method using Junit?

Instead of testing the main method, why not do a little refactoring so that
your main method just calls a few procedures that you can test?

In the example you gave, the code in your main() method was doing several
things: reading some data, performing some calculations, and writing some
output. You could create functions for each of these that may be easily
tested individually.

   -----> kell


1. Testing JNI-ridden Java code using JUnit!

The Problem:

  We have used JNI to give Java developers a chance to use our C++
messaging system.  However, these JNI methods are not available to us
at test-time, since we load our shared libraries dynamically.  When we
write JUnit tests, or even try to run the software outside of the
system, we get UnsatisfiedLinkErrors, because the JNI methods cannot
be found because they exist in shared libraries that have not been

Is there any tricks, short of overhauling the system, to get around
Perhaps maybe even a pre-processor directive like #define or #pragma
in C++?


AJ Mieskolainen

2. Chicago Atarians of Old...

3. Testing private members using Junit

4. windows 2000 cant see network printers

5. Unit tests for JUnit (Was: Unit tests for GUI programming?)

6. email

7. JUnit and Cactus: Could not invoke the suite() method

8. MemTurbo vs. FreeMem

9. Test cases organization (JUnit, Ant...)

10. JUnit: Generic interface testing

11. Measure time for each single test in JUnit

12. Code generation of JUnit test cases

13. JUnit Test Question