Import a module so that it can be tested
suggest changeClasses, structs, enums, and their methods are internal by default. They can only be accessed from the same module. Test cases live in a different target, so they are a different module. Import the module under test with @testable. That import does not expose private members.
Let’s say we have a main module called ToDo and we want to write tests for it. We would import that module like this:
@testable import ToDo
All test methods in the file with this import statement can now access all internal classes, structs, enums and all their internal methods of the ToDo module.
You should never add the files with the elements you want to test to the test target because that can lead to hard to debug errors.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents