Dependencies:
- If application uses third party libraries or cocoa pods, then those libraries or pods are needed to be install for test as well.
- Test class (Test Suit) extends XCTestCase.
Get brushed up before starting:
-
All test classes have two methods in common setUp & tearDown.
-
setUp runs before every testcase & tearDown after every testcase.
-
Test cases runs alphabetically.
-
In Test Driven Development, it is good to create dummy test data first.
-
Test case methods starts with "test" keyword.
-
Test methods accept no parameters & return no value.
Appendix:
There are several other methods for comparing the expected result & actual result out of an operation.
Some of those methods are listed below:
- XCTAssertNil(expression, comment) generates a failure if expression != nil.
- XCTAssertNotNil(expression, comment) generates a failure if expression = nil.
- XCTAssert(expression, comment) generates a failure if expression == false.
- XCTAssertTrue(expression, comment) generates a failure if expression == false.
- XCTAssertFalse(expression, comment) generates a failure if expression != false.
- XCTAssertEqualObjects(expression1, expression2, comment) generates a failure if expression1 is not equal to expression2.
- XCTAssertEqualObjects(expression1, expression2, comment) generates a failure if expression1 is equal to expression2.
- XCTAssertNotEqual(expression1, expression2, comment) generates a failure if expression1 == expression2.
- XCTAssertEqual(expression1, expression2, comment) generates a failure if expression1 != expression2.
- XCTAssertGreaterThanOrEqual(expression1, expression2, comment) generates a failure when ( expression1 < expression2).