XCTest for a Mac command line application

I want to test a command line application, but import XCTest gives me a message that the underlying module cannot be loaded.

How can I test a simple "hello world" command line App?


So, you have a simple command line app with main.swift/main.m and maybe some other code.

By default you have only one target with the same name as your product.

Press the "project" file, and you'll get smth like this:

The blue icon in the left-top corner is your project's file, and in the right-bottom part you have a list of targets.

enter image description here

Press the "+" button, and select MacOS Unit testing Bundle: enter image description here

Name your testing bundle somehow, e.g. test: enter image description here

Now your project contains 2 targets: one "main" (named the same as the project) and one "testing".

When adding a new file, don't forget to add it to the testing target (the checkbox under the Targets section ): enter image description here


Please note that this type of testing target is Logic tests, not Application tests, for more info look here: https://forums.developer.apple.com/thread/52211