Put Test Files Next to Production Code for Better Discoverability?
The Kickstarter engineering team posted an interesting proposal: put your XCTestCase
files into the same directory and group as your production code. Do keep the separate target ownership, of course.
One clear benefit is directory tree or file management, and discoverability of tests for people browsing the code: In most cases, you have FooService
in FooProject/FooApp/FooService.swift
, and FooServiceTests
in FooProject/FooAppTests/FooServiceTests.swift
. With nested folders, you need to navigate around even more. I got used to this Xcode default. But I also got annoyed by this split at the root level when I browsed code on GitHub. Multiple tabs in a modern browser to the rescue, this was never that problematic, given the test directory is structured in a similar way. If not, good look finding the file you’re looking for. (I hate that the RxSwift project, which I often had to browse to look up an implementation detail, has files that contain only a path reference to the real file, similar to ../../Core/SomethingSomething.swift
, making tests pretty hard to find).
I will try this approach with a library module that I develop as a sub-project of The Archive and report back.