Setting up Unit testing on Mac OS command line tool application

Can anyone point me to an example or instructions on how to successfully setup Unit Tests on a command line tool application? I’ve gotten close. The tests will compile, but as soon as they run and try to create a var from a struct within the app, I get errors like:

Undefined symbols for architecture x86_64:
“TestApp.MyStruct(Swift.Int) → TestApp.MyStruct”, referenced from:
TestAppTests.TestAppTests.testExample() → () in TestAppTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any help would be greatly appreciated!

-james

@fossfool Thanks very much for your question!

I apologize for my ignorance, but are you working within Xcode, and trying to add Unit Tests to an existing application? I guess I’m a bit confused with what you mean by a “command line tool” application. Is that simply the nature of what your macOS app? Just wondering.

Hey Syedfa,

I was referring to the Swift project type, “Command Line Tool.” If you are in Xcode click on File > New > Project… Then click on macOS at the top, and finally Command Line Tool and press next. You’ll notice you don’t have the option to “Include Unit Testing” like you do under Cocoa App, or Game project templates.

This means you have to manually add Unit Test after Xcode sets up the project. I’m having trouble getting everything setup correctly and the Unit Tests working against the target project.

I’m getting that error above when I try to compile the test. I’m hoping someone might be able to tell me why.

Best,
-james

This topic was automatically closed after 166 days. New replies are no longer allowed.