Search code examples
swiftxcodeunit-testingxctest

Why do I get "Missing required modules" when using @testable import MyApp while unit testing my Swift app?


For clarification, image has been attached.

Error message

As you can see I am expected to import the modules of my application when importing it into a unit test file.

In order to fix this issue:

  1. Click on your Test target.
  2. Click on Build phases.
  3. Click on Link Binary With Libraries
  4. Add required libraries.

This question has been edited to be more clear and useful to others. @soundflix


Solution

  • Dependency declarations aren't transitive. When you import your production code, that doesn't also import the libraries your code depends on. So when your test code has any references to those libraries, they also must be imported. And from my experience, the libraries must also be linked into your test bundle.