Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
mohit.khatri28@gmail.com - 18 Apr 2007 10:41 GMT
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
Eric Sosman - 18 Apr 2007 13:41 GMT
> Hi All,
>
[quoted text clipped - 8 lines]
>    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.

Signature

Eric Sosman
esosman@acm-dot-org.invalid



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.