Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing internal classes in swift framework

I did not find a way to unit test an internal swift class that is inside a framework. It only works if I set the class scope to public. Is there a way around it ?

Here is what I have now:

In the framework:

class InternalClass {}

In the tests:

import XCTest
@testable import MyFramework
class InternalClassTests: XCTestCase {
  let sut = InternalClass() //ERROR HERE Use of unresolved identifier 'InternalClass'
}
like image 869
Stanislas Heili Avatar asked Oct 19 '25 13:10

Stanislas Heili


1 Answers

You can use the @testable before your framework import in your unit test file like

@testable import MyFramework

which give you access to at least your internal method and classes in your framework.

like image 98
Nicolas Manzini Avatar answered Oct 22 '25 01:10

Nicolas Manzini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!