Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to test a method which has void return type and no arguments?

Reply
Thread Tools

How to test a method which has void return type and no arguments?

 
 
mohit.khatri28@gmail.com
Guest
Posts: n/a
 
      04-18-2007
Hi All,

I am using JUnit for testing java application under Eclipse IDE. I
have a method which has void return type and no arguments i.e.

void xyz()
{
..............
}

Could anybody suggest me how do i test this type of method using
JUnit.

Thanks & Regards
Mohit

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      04-18-2007
wrote:
> Hi All,
>
> I am using JUnit for testing java application under Eclipse IDE. I
> have a method which has void return type and no arguments i.e.
>
> void xyz()
> {
> ..............
> }
>
> Could anybody suggest me how do i test this type of method using
> JUnit.


Such a method only makes sense if it makes changes that
are observable through other means -- java.util.Set#clear(),
for example, takes no arguments and returns no value, but
changes the state of a Set in ways other methods can observe.

The way to test clear() is not to observe its behavior
directly, but to observe what happens to the Set when you
use it. A plausible unit test might apply clear() to Sets
in various states -- brand-new, with one element, with a
hundred elements, just-cleared, after insertion and individual
removal of elements -- and then use Set's other methods to see
whether clear() has had its intended effect: call isEmpty(),
or call size(), or call iterator().hasNext(), and so on.

Test your xyz() the same way. Figure out what effect it
is supposed to have in various circumstances, and use other
methods to verify that the effect has in fact occurred. If
xyz() is supposed to throw an exception in some cases (as
clear() is), that's another thing you can check.

--
Eric Sosman
lid
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to test a method which has void return type and no argument? mohit.khatri28@gmail.com Java 10 04-24-2007 10:40 AM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57