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

Discussion in 'Java' started by mohit.khatri28@gmail.com, Apr 18, 2007.

  1. Guest

    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
     
    , Apr 18, 2007
    #1
    1. Advertising

  2. Eric Sosman Guest

    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
     
    Eric Sosman, Apr 18, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ollej Reemt
    Replies:
    7
    Views:
    537
    Jack Klein
    Apr 22, 2005
  2. Replies:
    5
    Views:
    841
    S.Tobias
    Jul 22, 2005
  3. Replies:
    10
    Views:
    3,854
    Patricia Shanahan
    Apr 24, 2007
  4. Skybuck Flying

    test(void *data) vs test(void &data)

    Skybuck Flying, Jun 18, 2011, in forum: C Programming
    Replies:
    91
    Views:
    1,638
    Shao Miller
    Jun 27, 2011
  5. Skybuck Flying

    Re: test(void *data) vs test(void &data)

    Skybuck Flying, Jun 19, 2011, in forum: C Programming
    Replies:
    5
    Views:
    363
    Angel
    Jun 19, 2011
Loading...

Share This Page