I have a bunch of tests for my macOS app. It is XCTest.
Being run the last test turning on whole OS theme to dark, so I need every time to go to the System settings changing it back manually. I did not program such behavior.
macOS Sequoia 15.2 Xcode 16.2
import XCTest
@testable import TipCalculatorMac
final class TipCalculatorAppTests: XCTestCase {
func testRemoveRow() {
let viewModel = BillViewModel()
viewModel.rows = [
BillRow(billAmount: 100, tipPercentage: 10),
BillRow(billAmount: 200, tipPercentage: 20),
]
let initialCount = viewModel.rows.count
viewModel.rows.remove(at: 0)
XCTAssertEqual(viewModel.rows.count, initialCount - 1, "Removing a row should decrease the count of rows by 1")
}
}
import XCTest
final class TipCalculatorMacUITestsLaunchTests: XCTestCase {
override class var runsForEachTargetApplicationUIConfiguration: Bool {
true
}
override func setUpWithError() throws {
continueAfterFailure = false
}
@MainActor
func testLaunch() throws {
let app = XCUIApplication()
app.launch()
// Insert steps here to perform after app launch but before taking a screenshot,
// such as logging into a test account or navigating somewhere in the app
let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = "Launch Screen"
attachment.lifetime = .keepAlways
add(attachment)
}
}