Results 1 to 6 of 6
  1. #1
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Junit Testing Boolean methods

    Say I have a boolean method

    public static boolean hasPower() {


    In JUnit test case
    How would I start?

    is it:

    @
    public static boolean testhasPower() {
    // code
    return true/or false?
    }

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

    Default Re: Junit Testing Boolean methods

    You woudl write test cases that would check that setHasPower returns the correct value for different situations.
    So if running another method on the object should change hasPower to 'true' then you would add an assert check that comfirms that.
    It's not the sort of method that can be checked by itself.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: Junit Testing Boolean methods

    can you give me an example?

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

    Default Re: Junit Testing Boolean methods

    Without knowing the class you are testing, no.
    And even with it, what about my description is confusing?

    If all this class is is a model class consisting solely of setters and getters I, personally, wouldn't test it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: Junit Testing Boolean methods

    I was wondering if you could show me a skeleton of a Junit testcase for these examples please:

    a method that tests 5 cards and finds a pair (poker)
    a method that adds 2 numbers together
    a method that tests 5 cards and finds 4 of kind (poker)

    like a basic outline. I dont know where to start..

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default Re: Junit Testing Boolean methods

    Stop opening other thread for the same subject; I'm closing this one.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. JUnit Testing enQueue & deQueue Methods
    By Martyn in forum New To Java
    Replies: 1
    Last Post: 01-10-2013, 12:25 AM
  2. Junit testing, testing list<e> interface
    By mackavelirip in forum New To Java
    Replies: 0
    Last Post: 10-05-2011, 06:08 AM
  3. JUnit testing
    By hedonist in forum Advanced Java
    Replies: 4
    Last Post: 10-04-2009, 12:06 PM
  4. Replies: 1
    Last Post: 04-17-2008, 02:30 PM
  5. Testing JUnit PDE with Ant
    By keynan in forum Eclipse
    Replies: 0
    Last Post: 02-14-2008, 11:35 PM

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
  •