apollo-ios: ApolloTestSupport causes issue after upgrading from 1.0.7 to 1.1.2

Summary

Using Swift Package Manager, after updating from 1.0.7 to 1.1.2, the import of ApolloTestSupport causes the archive process failure. The build process is still working.

Version

1.1.2

Steps to reproduce the behavior Import ApolloTestSupport in any file, and the following code from TestMock.swift will generate an error:

#if !COCOAPODS
@_exported @testable import ApolloAPI
@testable import Apollo
#endif

Error: Module 'ApolloAPI' was not compiled for testing

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 6
  • Comments: 28 (10 by maintainers)

Most upvoted comments

I have three different release configurations to switch the environment in my project: Release Development, Release Staging, and Release Production. I’m encountering the mentioned issue only in the Staging and Production configurations.

Have you checked if any of your release builds / configurations directly or indirectly include any of Apollo’s generated mock or test packages? If that is the case, that is one reason why this leads to said error. This also includes ApolloTestSupport which may not be imported into any of your release builds.

So the first step I can recommend you is to make sure that no Apollo test packages are imported or used for your release builds.

The other case I described is when you use test builds with a different configuration that is not called “Debug” or whose name does not start with “Debug_”.

@AnthonyMDev I don’t have a test project, however, I did go in and check our linking and removed our generated Apollo API library from our test target. This allowed our tests to pass without erroring out on the JSONRequest.

Does anyone have a link to a Swift forum topic or documentation that provides a bit more insight into why this is needed?

You do realize that I’ve already given you an answer to this question a month ago?

I hadn’t realized but thank you.

Thanks for that note. Yes I just renamed our Testing to Debug_Testing

You have to change the name to Debug or prefix it with Debug_. For example Debug_DevStage. It’s a limitation of how Swift packages are compiled.

Does anyone have a link to a Swift forum topic or documentation that provides a bit more insight into why this is needed?

https://forums.swift.org/t/update-spm-to-support-custom-configuration-names/43075

We are aware that creating mocks outside of the test target is not the best approach and we are actively searching for an alternative solution to run UITests using mock responses without importing ApolloTestSupport into the main project target.

Have you tried the new selection set initializers? Do they not work for your use case?

thank you @calvincestari for the suggestion. The issue is resolved with the new selection set initializers, as we no longer need to import ApolloTestSupport in the main app target.

I’m so confused by this… Why would this cause an issue during archiving when the TestMocks are in a test support target. This target should not even be being built for archive builds. @calvincestari lets get on a call and chat about this one soon.