logic } testMethod1() —XCTestCaseObj1 testMethod2() —XCTestCaseObj2 ———————————————— - no arguments, - no return types, - begins with word “test” Collection How XCTest Works
initial state for all tests setUp() instance method scope - local to each test setup initial state before each test begins tearDown() class method scope - global to all tests final clean up for all tests tearDown() instance method scope - global to all tests clean up before each test ends setUp and tearDown
test method ends • Always invoked before tearDown() instance method • Can add multiple tearDown blocks, executed in LIFO order • Invoked on the main thread
check memory leaks by keeping a weak reference to the object in our test class • Check that the weak reference in nil the tearDown() method • Demo • Source: https://www.essentialdeveloper.com