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!

 
51
Kudos
 
51
Kudos

Now read this

Magical Future Swift Is (Almost) Here

I’ve been holed up dealing with Metal for a bit (which I was completely unfamiliar with, and therefore unable to blog about), but Swift 1.2 came out last week, rousing me out of my graphics-induced coma. And boy was I in for a surprise.... Continue →