Couple questions on Unit Testing Models

Discussion in 'iOS Programming' started by Dookieman, Jul 29, 2016.

  1. Dookieman macrumors 6502

    Joined:
    Oct 12, 2009
    #1
    Hey All,

    I want to write a unit test for my data model and ensure that it's parsing correctly. My approach is to make a JSON dictionary that has keys that mimic the server response and then manually set a model object with the same values as the JSON dictionary, then compare the two to ensure that the values are getting set appropriately. The problem is the XCTest is saying that the models aren't equal, even though they are (I iterated through each values and compared the values manually and got matching results). I double checked and they have the same values. The model inherits from NSObject so I don't need to implement equatable.

    1. Does XCTAssertEqual check memory address rather than values?

    2. Is there a way to compare these models without having to manually compare each value? e.g. model1.obj1 == model2.ob1
     
  2. jgaz macrumors member

    jgaz

    Joined:
    Dec 30, 2007
    Location:
    Colorado
    #2
  3. Dookieman, Jul 29, 2016
    Last edited: Jul 29, 2016

    Dookieman thread starter macrumors 6502

    Joined:
    Oct 12, 2009
    #3
    Awesome. I'll give it a try. Thanks for the link.

    Looks like it worked for me. I overrode the isEqual method like the blog suggested but figured that it would be best to write my own instead of touching Apple's.

    Thanks.
     
  4. jgaz macrumors member

    jgaz

    Joined:
    Dec 30, 2007
    Location:
    Colorado
    #4
    no problem. let us know what you discover.
     
  5. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    You should look at NSArray isEqualToArray: and NSDictionary isEqualToDictionary to see if they can help with this.
     

Share This Page