Browse Questions
- They test different layers of the app and run at different speeds.
- A memory leak is memory that is allocated but never freed — usually from retain cycles.
- Every UIView has a CALayer that does the actual drawing and compositing.
- SOLID is five principles for writing maintainable, extensible code.
Answer: They test different layers of the app and run at different speeds.
| Unit Tests | UI Tests | |
|---|---|---|
| What | Isolated logic | Full app user flows |
| Speed | Very fast (ms) | Slow (seconds) |
| Framework | XCTest | XCUITest |
| Dependencies | Mocked | Real app running |
| Flakiness | Low | Higher |
Code Example:
// Unit test — tests a function in isolation
class PriceFormatterTests: XCTestCase {
func test_formatPrice_returnsCurrencyString() {
let formatter = PriceFormatter()
let result = formatter.format(9.99)
XCTAssertEqual(result, "$9.99")
}
}
// UI test — launches the app and interacts with it
class CheckoutUITests: XCTestCase {
let app = XCUIApplication()
override func setUp() { app.launch() }
func test_addToCart_showsCartBadge() {
app.buttons["Add to Cart"].tap()
XCTAssertTrue(app.staticTexts["1"].exists)
}
}