swift - Running XCode tests (macOS app) turn on system dark mode unintentionally - Stack Overflow

admin2025-04-27  3

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)
    }
}
转载请注明原文地址:http://anycun.com/QandA/1745709613a91137.html