Is there a way to issue a warning when running tests with XCTest?
Asked Answered
T

2

8

I have a project that imports a Git submodule to run a part of an XCTest test suite. If the submodule is not available (not checked out), I want the test suite to succeed, but issue a warning that not all tests were run. Is that possible?

Trichroism answered 14/12, 2015 at 10:18 Comment(2)
I think this is not possible.Ipoh
I would like this, too, as I have tests for iOS9-specific code that I want to succeed when testing on iOS9, but not fail when testing on ≤8.Albion
B
2

Searching for similar issue I have found out that we could add messages to test logs as string attachments. If you want to have a warning sign you can add ⚠️ emoji in name. Here is a function example that adds it.

    func addLogMessage(_ message: String, attachmentLifetime: XCTAttachment.Lifetime = .keepAlways) {
        XCTContext.runActivity(named: "Log message") { activity in
            let messageAttachment = XCTAttachment(string: message)
            messageAttachment.lifetime = attachmentLifetime
            activity.add(messageAttachment)
        }
    }
Bondmaid answered 16/7, 2020 at 9:58 Comment(0)
O
0

I found this because I wanted to raise a "Not Implemented" warning on tests I was just laying out...

Eventually found this:

throw XCTSkip("Test not implemented")

Which I think makes a good alternative to a warning in the test results...

Olcott answered 6/9, 2024 at 9:9 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.