'Module was not compiled for testing' when using @testable

前端 未结 10 876
难免孤独
难免孤独 2020-12-04 14:00

I\'m trying to use Swift 2\'s new @testable declaration to expose my classes to the test target. However I\'m getting this compiler error:

10条回答
  •  情书的邮戳
    2020-12-04 14:33

    In my case I used a custom build configuration for testing (called Test) and also cocoapods as a dependency manager

    I had to add the following lines to the end of my Podfile to enable testability

    post_install do |installer|
        installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                if config.name == 'Test'
                    config.build_settings['ENABLE_TESTABILITY'] = 'YES'
                end
            end
        end
    end
    

    By default cocoapods sets ENABLE_TESTABILITY to YES only for Debug builds

提交回复
热议问题