No Such Module XCTest

Jul 30, 2020 11:30 · 240 words · 2 minute read

Framework importing XCTest not building pre-Xcode 11.4

I recently created a Framework which builds on top of XCTest to provide various XCUIApplication and XCUElement subclasses which model the structure of our app for usage in UI tests.

Unfortunately, I ran into an issue once it hit our CI server. When compiling pre-Xcode 11.4, you get this error message:

No such module 'XCTest'
	Failed to load module 'XCTest'

We still support Mojave, so at least half of our team are on that macOS version, that limits them to Xcode 11.3.1.

It’s also essential that we still execute our unit and UI tests on Mojave.

If we go back through the release notes for clues:

Xcode introduced an “Enable Testing Search Paths” build setting to improve support for test support frameworks and libraries. This build setting is on by default for test bundle targets, as well as for targets which explicitly include XCTest.framework in their “Link Binary With Libraries” list. Source files in such targets can now import XCTest without setting any custom search paths. (51117167)

Xcode 11.4 Release Notes

As an aside, I think of Xcode 11.4 as the ‘XCTest release’. It contains so many good things in there, many of which the WWDC ‘20 testing talks covered.

Anyway, to manually do the work of “Enable Testing Search Paths”, we need to add the following to the Build Settings:

SYSTEM_FRAMEWORK_SEARCH_PATHS = $(DEVELOPER_DIR)/Platforms/MacOSX.platform/Developer/Library/Frameworks $(inherited)

After that we should be good to go!