XCTest should support white-box testing of internal/private Swift classes
| Originator: | kristopherdjohnson | ||
| Number: | rdar://17751446 | Date Originated: | 21-Jul-2014 03:56 PM |
| Status: | Duplicate/17755128 | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6 (6A267n) |
| Classification: | Enhancement | Reproducible: | N/A |
Summary: The XCTest framework can be used to test Swift classes, and the tests themselves can be written in Swift. However, because the test bundle is (typically) separate from the module to be tested, XCTest can only be used to test types and functions that are public. Internal and private members of the module cannot be tested. The only workarounds available are to (a) make everything that you want to test "public" (and you usually want to test EVERYTHING) or (b) put the unit tests within the module to be tested and then somehow disable/remove them when building the app or framework to be shipped. Both of these workarounds have drawbacks, which discourage use of unit tests or discourage use of appropriate access control. It would be nice if there was a way to somehow inject the unit test bundle into the module to be tested, or some way to specify that the access level of a module member is "internal but testable". Steps to Reproduce: Create an iOS framework project in Xcode 6 with unit tests Write a class in the framework that is not "public" Write a unit test for the class Expected Results: Unit test should be able to run Actual Results: Unit test cannot be compiled because the element to be tested is not "public". Version: Xcode 6 beta 4
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!