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

前端 未结 10 825
难免孤独
难免孤独 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:11

    This didn't occur in my projects prior to Xcode 8, but after I upgraded to Xcode 8, it made me perplexed.

    The answers posted here didn't get my problems resolved. For me, I just ditched these tests as it is not needed. So uncheck the test buttons:

    And now the error has gone out.

    0 讨论(0)
  • 2020-12-04 14:16

    For those of you who are experiencing this only upon running Xcode Profiler: switch profile build configuration in your scheme management to the one that has testability enabled - and that would be debug in most cases:

    0 讨论(0)
  • 2020-12-04 14:22

    Make sure that you properly set your checkboxes under your app scheme. You SHOULD UNCHECK your test targets for Archive Build.

    0 讨论(0)
  • 2020-12-04 14:22

    If you trying to test framework:

    Go to test target -> Build Phase -> Create new copy files phase -> Choose frameworks -> Add all recursively used frameworks

    0 讨论(0)
  • 2020-12-04 14:25

    This is probably because your main target Enable Testability is set to NO. You should set it to YES in the debug scheme (which is used for running your tests).

    If you use Carthage, this problem can be caused by importing frameworks with @testable, because they are built with a release scheme.

    Most of the times it's bad practice to import frameworks with that prefix, so you could avoid it. If you can't, you should Enable Testability in the frameworks' release scheme. https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html#//apple_ref/doc/uid/TP40001051-CH1-SW326

    0 讨论(0)
  • 2020-12-04 14:28

    If by any chance you have

    install! 'cocoapods',
             generate_multiple_pod_projects: true,
             incremental_installation: true
    

    Then, this is the way to do it.

        # generated_projects only returns results if the we run "pod install --clean-install"
        # or install a pod for the first time
    
        installer.generated_projects.each do |project|
            project.build_configurations.each do |configuration|
                configuration.build_settings["ENABLE_TESTABILITY"] = "YES" 
            end
        end
    
    0 讨论(0)
提交回复
热议问题