Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

xctest

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?

like image 998
zoul Avatar asked Nov 09 '22 23:11

zoul


1 Answers

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)
        }
    }
like image 163
Tomasz Wronka Avatar answered Nov 24 '22 00:11

Tomasz Wronka