Xcode How To: Naming Your Tests

I noticed something that might be of interest to y’all.

At one point I asked my team if the preference was to name test files as MyFileTests or TestMyFile.

I’ve noticed that for test files that end with Tests you get this nice output in the Counterparts menu where the test and the implementation file are linked.

This only works if the test is named MyFileTests and there isn’t any deviation. (ex. MyFile and MyFileTests and not TestMyFile)

What does Xcode show?

Screenshot of Xcode counterparts menu showing tests when test file ends with the word Tests

Screenshot of Xcode counterparts showing test file and file name when test file name ends with the word Tests

Screenshot of Xcode counterparts menu not showing tests when the test file name is prefixed with the word Test

Xcode How To: Run Tests Without Running All Tests

TIL: if you are running the same test case over and over you can mash ⌃⌥⌘G and Xcode will rerun the last test case you just ran.

Importantly this will just run whatever you had run just before. So if it’s a whole test case, it runs that again. If it’s a single test it will run that again. If it’s multiple tests, it will run that again.

From a friend: It also preserves the run many times aspect. So if you're running 1000 times, you can keep hitting it to run 1000 more times.

You can also run “selected” tests with ⌃⌥⌘U so if you select some text, you can run the tests within that selection.

Where can I find these in the Menu bar?

These options all live in the Product menu under Perform Action labeled as Test and Test Again.

How did I find this?

The reason I stumbled upon this was because I was adding tests to a file that exists and it’s taking me a couple tries to get it all right. I want to be able to edit the setup steps and then run the XCTestCase again without running the entire Test Scheme or Test Plan. I looked into Xcode key bindings to see what was there and found this.

Hope it can help someone else!

How to fix WatchKit app WeatherKit issues

I made an iOS app that used WeatherKit. Everything was working as expected and recently I wanted to add an WatchOS component. Because I am adding the watch app to an existing iOS app, I added the target in Xcode and made sure to update the capabilities to the watch app so that it could use WeatherKit too.

Unfortunately I kept running into an auth error where when running the watch app, WeatherKit couldn’t created a jwt and therefore no weather data was making it to the app.

I then went to developer.apple.com and tried to add an identifier for my watch app but it wouldn’t let me. Saying the identifier was invalid. Argh!!! I was so confused.

I thought “maybe I need to wait a couple days for some process to complete”, but still no luck.

Finally I decided I’d make a fresh watchOS/iOS app and plug my weather framework into that, create a new identifier and everything would surely work. Right?!

Well then I get the exact same error in the developer portal! What the hell is going on.

Here is the important part: it turns out that in some cases Xcode automatically creates identifiers in the developer portal. You may see a bunch of identifiers that start with XC.

Then I realized that my watch kit app identifier was there the whole time! …if only the developer portal errors were clearer about why I couldn’t create a new identifier…

Anyways, then I clicked on my watchkitapp identifier, added the capability and the service for WeatherKit and voila, it worked!!!

tl;dr if you’re unable to create an identifier in developer.apple.com, check that the identifier wasn’t already automatically created for you. 🤷🏽‍♂️