Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 257 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'Module was not compiled for testing' when using @testable

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

![enter image description here][1]

`Intervals` is the module that contains the classes I'm trying to expose. How do I get rid of this error?

[1]:
Reply

#2
I got this when my new Tests.swift file belonged to the wrong Target.
Reply

#3
I'm a beginner and I just can't remember where all the settings and options are in Xcode. So I always feel frustrated when I see "you can set xxx to yyy ..." in answers to this kind of question. Where are those xxx in Xcode? and What are those yyy? We need a map showing how we get things done, but not another clue, like xxx. It seems we are Nicolas Cage in National Treasure!

Thanks for all the clues here, very much! You really help me. But I have a concrete answer here (which is actually from you):

1. Select the main target of your project
2. Go to the "Build Settings" tab
3. Turn on the "All" option
4. Search for the "Build Options" section
5. Set "Enable Testability" to "Yes"
6. Wait for a few minutes or restart Xcode (then the error disappeared)
Reply

#4
If by any chance you have

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

Then, this is the way to do it.

```ruby
# 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
```
Reply

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

[![enter image description here][1]][1]


[1]:
Reply

#6
I started getting this error when running tests using Bitrise.

Unlike other users says, this **is not** per `Target` basis, or per `Schema` basis, it **is** per `Configuration` basis.
Select `Target` -> `Build Settings` tab -> look for `testability` -> Enable it on the **Configuration that you are using**.

Please notice that Apple recommends to enable this on the configuration that you are using for debugging, not for AppStore.
Reply

#7
**If you trying to test framework:**

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

#8
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
Reply

#9
Above solution is fine if you are using pods/Carthage.
But if you are using frameworks from iOS itself 'e.g. Contacts', you need add path to these frameworks in 'Library Search Paths' of your main project's target.
[![enter image description here][1]][1]


[1]:
Reply

#10
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:

[![enter image description here][1]][1]


[1]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through