java unit test

C

Chenxi

hello

i've written a small programme and want to test the main method. the problem
is that if the parameters are wrong and the programme terminates, JUnit
cannot detect it and the test result would be pass. if i use System.exit(1),
JUnit cannot catch the termination status and the result will be that the
test is still running.

How can i let the unit test know whether the programme fails or succeeds?

==================
public class A{

public A{}

.......

public static void main(String[] args){
if (args.length<2){
System.out.println("wrong parameters");
return;
// System.exit(1);
}

......

}
=================
--
 
A

Andrew Thompson

How can i let the unit test know whether the programme fails or succeeds? ...
public static void main(String[] args)

throws IllegalArgumentException {
if (args.length<2){

throw( new
IllegalArgumentException("Must be at least 2 parameters") );
....

? (just a thought, untested)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top