Use Xcode's Test Classes Assistant Editor with Swift Classes Use Xcode's Test Classes Assistant Editor with Swift Classes xcode xcode

Use Xcode's Test Classes Assistant Editor with Swift Classes


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.


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.


It seems that on Xcode 8 it automatically setup the suitable test class in the assistant editor after you import the original class inside the test class.

@testable import YOUR_MODULE_NAMEclass MyViewControllerTests: XCTestCase {    var myVC : MyViewController!}

After that you will find MyViewControllerTests on the assistant editor under "Tests Classes".