Command Line Tool target cannot have a Unit Testing Bundle

I tried to add unit tests for my Command Line Tool in Xcode but I couldn't specify the Target to be tested as I wanted. Are there any workarounds for this, while still maintaining the platform? I also tried swift run with dynamic linking for XCTest but couldn't seem to link the Command Line Tool target. Please let me know if this is possible, or if not, the reasoning behind this behaviour.

Thanks again for the help.

Best workaround I know is to write a very simple main.swift that essentially just calls one routine with the command line arguments and returns an error code result. Everything else, including your current main entry point, gets put into a module/framework, which can be tested with XCTest.

Thanks @jonprescott. Just to confirm (I am still relatively less experienced) I think you are suggesting package the CLT into a framework, and expose the methods I need to use in a separate platform target (which can have unit tests). Probably will have to do this.

Terms of Service

Privacy Policy

Cookie Policy