A Gotcha When Testing Swift Frameworks with Xcode 6

After spending most of the summer delving into what Swift can and can’t do as a functional programming language, I’ve turned my attention to writing real library code in Swift. I do have a day job, after all, and while thinking about Magical Future Swift is a fun exercise, I still need to learn how to do the basic everyday things. Which is where I was tripped up by the default framework test settings.

The issue occurred when I created a new Cocoa framework project, in Swift. By default these come with tests, so you’d be forgiven for thinking that the tests just run when you type Cmd-U, as they would for an app. You would be wrong, however. Most of the “Product” menu is disabled and gives that heart-sinking “you can’t do what you think you can do” sound when you try the shortcuts.

What happens is that by default, the test bundle is not added to the test configuration of the framework’s build scheme. Here’s how you reenable it. Say you named your framework “test” (I’m creative like that). Select it and then select “Edit Scheme…”:

edit-scheme.png



Then go to “Test” and hit the + in the lower left-hand corner of the detail view:

add-tests.png



Select your test bundle (my clever naming pays off dividends…):

select-bundle.png



Make any modifications you want — in this case, let’s add a location for the tests to run against, and click “Close”:

finish.png



Now all your testing shortcuts should be enabled and working (your running shortcuts still won’t be, since a framework can’t be run on its own).

Happy testing!

 
52
Kudos
 
52
Kudos

Now read this

Error Handling in Swift: Might and Magic

If distance brings perspective, proximity brings understanding. Concepts that were remote and downright strange when I played with them in Haskell or read about them in Scala are blindingly obvious solutions to any number of problems now... Continue →