How do I setup a Unit Test for Swift?

前端 未结 2 1176
遇见更好的自我
遇见更好的自我 2021-01-13 10:32

I feel it prudent to attempt to master Unit Testing/Swift.
I viewed WWDC\'s Objective-C version and pretty much understand the Objective-C paradigm: importing the head

2条回答
  •  礼貌的吻别
    2021-01-13 10:54

    The solution recommended by Steve Rosenberg is an easy one but leads to issues that are hard to debug (an instance of which is documented here if you're interested).

    The recommended approach is to edit your app target's (not the test target) Build Settings and set "Defines Module" under Packaging to YES.

    With that done, in your test target, at the top of each .swift file, import your projects main module to get access to your classes, structs, etc. The name of the main module is typically the same name as your Xcode project file.

    Note: When following this approach, you will have to annotate all class/struct/enum methods that you want to test with the public access control modifier.

提交回复
热议问题