tezvyn:

setUp() and tearDown() in XCTestCase

Source: interviewintermediate

WHAT IT TESTS: knowledge of XCTest lifecycle and test isolation. OUTLINE: setUp builds fresh state before each test, tearDown cleans up after, ensuring independence. RED FLAG: thinking they run once per class or sharing mutable state across tests.

WHAT IT TESTS: understanding of the XCTest lifecycle and why test isolation matters. ANSWER OUTLINE: setUp runs before every test method to create a clean fixture, like a fresh system-under-test and mocks, so no test depends on another's leftover state. tearDown runs after each method to release resources, reset singletons, or delete temp files. Both run per test, not once per class, unless you use the class variants. RED FLAG: believing they run once for the whole class, or letting state leak between tests.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

setUp() and tearDown() in XCTestCase · Tezvyn