2
votes

I have a project that is mixed Obj-C and Swift and I am having some issues getting my unit tests to work.

I'm using the @testable import moduleName directive to import my files, however it does not appear to be importing all the files. I have full access to pretty much all of my Obj-C models, manager classes etc. but none of the view controllers (95% of which are in Obj-C) are available from within the XCTestCase, along with all of my Swift files.

I have imported @testable import ModuleName at the top of the XCTestCase, I have also edited the target to enable testability, but the only way I can access these files seems to be if I set the files target membership manually, which if I have understood everything correctly, I should not need to do.

Any suggestions?

1
What did you mean by but none of the view controllers are available? did you mean that you can not access any of the variables inside your file view controllers classes?A.Munzer
Sorry, not so clear. What I mean is none of my view controllers (all Obj-C) are available to me inside my XCTestCase class along with all of my Swift files, but other classes are available to be used as expected. Edited question to clarify.darkbreed

1 Answers

4
votes

Yeah I just also went from the same problem about the Unit testing with the project having both Objective-C & Swift languages. So basically what i found was You have to add the respective file and all the required files to Test target. And also required to add them to the Bridging_Header to access those files Moreover the reason behind using the @testable is to test methods internal .... methods.

@testable import moduleName

This is used for the purpose of visibility of methods, i.e like internal methods can now be visible in unitTest but atill private methods won’t.