I have a framework/module written in Objective-C and want to test its external interfaces and internals in Swift. For that I created a new test target in the same project, targeting the framework. In the Swift code I can import the module and use the public classes without a problem. However, I can't access the internal classes in my tests.
I tried the following:
@testable import
feature of Swift 2 in Xcode 7, but that doesn't seem to work (yet) for Objective-C frameworks.What I came up with is to manually import all privat sources I want to test in the bridging header of the test target. That works. However, it doesn't feel like it's the intended way of testing an Objective-C framework with Swift.
Any ideas on how to do that better?
The way I have handled such issues in the past is to make public classes within the framework that subclass your internal classes that you want to test. You can add compiler flags to make them only built with debug or test configurations.
For instance, if you had a class called SomeClass
, you would have SomeClassTest
that would override all the methods publicly. Doing this also gives you the handy ability to easily include test logic, such as inserting dummy data where needed etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With