Objective-C Language Testing a block of code or some method:


Example

  • Import the class, which contains the method to be tested.
  • Perform the operation with dummy data.
  • Now compare the result of operation with expected result.
- (void)testReverseString{
NSString *originalString = @"hi_my_name_is_siddharth";
NSString *reversedString = [self.someObject reverseString:originalString];
NSString *expectedReversedString = @"htrahddis_si_eman_ym_ih";
XCTAssertEqualObjects(expectedReversedString, reversedString, @"The reversed string did not match the expected reverse");
}

Feed the dummy data to the method under test if required & then compare the expected & actual results.