Results 1 to 5 of 5
  1. #1
    minama's Avatar
    minama is offline Member
    Join Date
    Dec 2011
    Posts
    9
    Rep Power
    0

    Default JUnit test for void mehtods

    Hello,

    I have a class, it has some methods, which I need to test. The problem is, that some of those methods are void. I use mocks for dependencies. So some of those mock methods return values and some of them dont(they just do some "work" inside their own class). So, if anybody has any idea? I can not post the code, it is too complicated.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: JUnit test for void mehtods

    Presumably the void methods do something, so test that something.
    Is there a state change? That is, does some data within the object being tested change?
    Is there a mocked object they need to call with specific values? Then test that with your mocking framework of choice.

    Not sure what else to say, really.

  3. #3
    minama's Avatar
    minama is offline Member
    Join Date
    Dec 2011
    Posts
    9
    Rep Power
    0

    Default Re: JUnit test for void mehtods

    this method inside has some objects, whose state is changing... I'll try to test them. Thx

  4. #4
    minama's Avatar
    minama is offline Member
    Join Date
    Dec 2011
    Posts
    9
    Rep Power
    0

    Default Re: JUnit test for void mehtods

    still, dont know what to do, I can not change the tested class, that's why I have no idea how can i test the method, which uses only mock objects or local objects to save changes...

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: JUnit test for void mehtods

    If you can't test the data in the class, and you can't test whether interfaces with other parts of the system are called (ie mock objects) then you can't test the method.

    If you can test calls to mocked objects, and/or the data after the method under test is called then you can test it.

Similar Threads

  1. problem with JUnit test
    By exltus in forum Advanced Java
    Replies: 12
    Last Post: 12-19-2011, 07:49 PM
  2. How to test a void method in Junit?
    By jRookie in forum New To Java
    Replies: 7
    Last Post: 09-01-2010, 07:47 AM
  3. Replies: 1
    Last Post: 08-03-2009, 05:31 PM
  4. JUnit Test Help!
    By pharo in forum New To Java
    Replies: 0
    Last Post: 04-10-2009, 05:15 PM
  5. Junit test
    By alice in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 01:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •