title: Unit Testing - What to test?
body: <p>So, I've done some reading on the advantages of Unit testing and creating test cases / suits in Xcode. I can see the advantages of this for avoiding things like regression and making sure new commits / builds don't break existing code. </p>
  
  <p>What I am trying to figure out though - what do I test? </p>
  
  <p>Do I create tests for every class I create? </p>
  
  <p>At the moment, I am at the start of my project and I am busy creating a lot of model objects - these classes don't do that much - mainly to hold data that I parser in (from XML). Should I be creating test cases to make sure that each requirement of each object is met?</p>
  
  <p>Taking the above example - if I wrote a single test suit like this for one of my model objects: </p>
  
  <pre><code>import &lt;XCTest/XCTest.h&gt;
  #import "BBError.h"
  
  @interface ErrorObjectTests : XCTestCase
  
  @end
  
  @implementation ErrorObjectTests
  {
      BBError *error;
  }
  - (void)setUp
  {
      [super setUp];
      // Put setup code here; it will be run once, before the first test case.
      error = [[BBError alloc]init];
  }
  
  - (void)tearDown
  {
      // Put teardown code here; it will be run once, after the last test case.
      [super tearDown];
  
     error = nil; 
  }
  
  
  -(void)test_HasValidErrorCodeMessage
  {
      error.code = @"Error Code";
  
      XCTAssertEqual(error.code, @"Code error",
                     @"BBError should have valid error code message");
  
  }
  </code></pre>
  
  <p>Now if for some reason in my app - I set error.code to nil or don't assign an error code to it - will this test then fail?</p>
  
  <p>I'm having trouble understating why it would fail then - because in the actual test method - I am assigning error.code to a string value. Should I leave this value out and then where I use this object, make sure error.code has a value in order for the test to pass? </p>
  
  <p>P.S: Yes, I am aware that this particular test might not be the most accurate as I might not always getting an error in the first place - but this is just an example </p>
  
  <p>Appreciate any input guys. </p>