Spot the bug
These tests pass alone but fail when run together. Tap the cause.
final class CartTests: XCTestCase {static let cart = Cart()func testAddItem() {Self.cart.add(.apple)XCTAssertEqual(Self.cart.count, 1)}func testRemoveItem() {Self.cart.add(.apple)Self.cart.remove(.apple)XCTAssertEqual(Self.cart.count, 0)}}
Hint 1 of 1
What carries over from one test to the next?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 2
static let cart = Cart()
Line 2 shares one cart across tests, so results depend on order. Create a new Cart in each test or in setUp.