Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Xcode's Test Classes Assistant Editor with Swift Classes

When working in Xcode, it's often nice to pull up unit test cases in an assistant editor. Currently, I've been selecting the tests file manually, but I see the assistant editor has an option for Test Classes.

I've tried to get this option to pull up my tests file automatically, but I can't seem to make it work. Is there some sort of configuration required for it? Does it just not work for swift projects?

like image 244
esthepiking Avatar asked Dec 17 '15 17:12

esthepiking


2 Answers

The assistant editor can automatically open the companion file in many cases. However, afaik, there is no automatic setting for opening the unit test.

To get the behavior you want you can fuzzy search with open quickly ++o then open the result in the assistant editor with +.

You might also find use in open quickly ++o then +.

You can see more about "Working Efficiently with Xcode" here.

like image 160
bennyty Avatar answered Nov 19 '22 02:11

bennyty


The shortcuts mentioned in other answers work great, but they don't make the assistant editor automatically work with test classes. Turns out it didn't work with swift code previously, but Apple just added support for this to Xcode 9:

A file with a base name of FooTest or FooTests is now considered a counterpart of a file with a base name of Foo for navigation and the Assistant Editor. (28981734)

So, with Xcode 9, the test target filename needs to have the same name as the main code file + either 'Test' or 'Tests' and the Xcode test classes assistant editor will work automatically.

like image 24
esthepiking Avatar answered Nov 19 '22 01:11

esthepiking