Results 1 to 8 of 8
  1. #1
    Drun's Avatar
    Drun is offline Member
    Join Date
    Nov 2009
    Location
    Indian Head, MD (Missing Pittsburgh PA)
    Posts
    44
    Rep Power
    0

    Default JUNIT testing assertEquals function

    I am looking into Junit testing, looks for the most part to be simple, but one thing that I am seeing is some sites say assertEquals takes 3 paramaters String(message about what being tested), Object(the object being tested can be a real Object or the primative type being retruned), Object(what you expect it to be equal to). And other sites have it as 2 paramaters, the 2 Ojbects(in the same order)

    Now my questions are, 1) is there 2 versions of the assertEquals (yes I am ignoring the floating point one, that has the finnal paramater for tolorance) 2) if the anser to 1 is no, which is correct.
    Michael P. O'Connor
    http://www.mikeoconnor.net

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    The api would clear this up for you, you know, but there are two.

  3. #3
    Drun's Avatar
    Drun is offline Member
    Join Date
    Nov 2009
    Location
    Indian Head, MD (Missing Pittsburgh PA)
    Posts
    44
    Rep Power
    0

    Default

    Ok that did help alot, but what I did not see, and wondering if exists, is if I can test for non-equal to (mind you same will not work) so lets say in some case I have a class that has a member varable x, and I want to test for it to be anything but 0. Is there a way I can set it up to test for 0 and fail if it is equal to zero.
    Michael P. O'Connor
    http://www.mikeoconnor.net

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    assertTrue()?

  5. #5
    Drun's Avatar
    Drun is offline Member
    Join Date
    Nov 2009
    Location
    Indian Head, MD (Missing Pittsburgh PA)
    Posts
    44
    Rep Power
    0

    Default

    I don't think that would work as it would take a boolian, and I am looking for the ability to test for equal between to random Objects, could be int, float, randomDrunMadeObjectThatHasIsEqualOverLoaded, what ever.
    Michael P. O'Connor
    http://www.mikeoconnor.net

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

    Default

    Quote Originally Posted by Drun View Post
    I don't think that would work as it would take a boolian, and I am looking for the ability to test for equal between to random Objects, could be int, float, randomDrunMadeObjectThatHasIsEqualOverLoaded, what ever.
    You're thinking too much of JUnit; a simple assertTrue(YourClass.x != 0) should do the job.

    kind regards,

    Jos

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Exactly.
    Or, for some random object:
    assertTrue(!myRandomObject.equals(anotherRandomObj ect));

  8. #8
    Drun's Avatar
    Drun is offline Member
    Join Date
    Nov 2009
    Location
    Indian Head, MD (Missing Pittsburgh PA)
    Posts
    44
    Rep Power
    0

    Default

    ok thanks JosAH and tolls, I guess I was looking so hard I did not see the anser right infront of my face.
    Michael P. O'Connor
    http://www.mikeoconnor.net

Similar Threads

  1. Replies: 3
    Last Post: 12-04-2009, 03:08 PM
  2. JUnit testing
    By hedonist in forum Advanced Java
    Replies: 4
    Last Post: 10-04-2009, 12:06 PM
  3. Testing tools (Profiling and JUnit)
    By ericpinet in forum Eclipse
    Replies: 1
    Last Post: 04-21-2009, 10:23 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

Posting Permissions

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