本文介绍了如何在发布模式下启用框架的可测试性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 iOS 应用项目,由 Swift 3.0 编写工作区包含我们团队构建的动态框架,用于在整个项目中共享可重用的代码和资源.

I have an iOS app project, written by Swift 3.0the workspace contains a dynamic framework build by our team, for sharing reusable codes and resources all across the Project.

我们使用Activate Compilation Conditions来切换生产服务器url和beta服务器url,如下:

We use Activate Compilation Conditions for switching production server url and beta server url, like this:

#if DEBUG
let url = "http://my-beta-server-url"
#else
let url = "http://my-production-server-url"

这样当应用程序被归档时,该 url 将切换到生产服务器 url.并且在调试时,我们可以使用测试版服务器进行开发.

So that when app is Archived, the url will switch to production server url.And when debugging, we can use the beta server for development.

我们有一个单元测试目标来测试这个框架.最近我们想添加一个简单的健全性测试来检查 url 在 Release 模式下是否正确.

We have an unit test target for testing this framework.Recently we'd want to add a simple sanity test for checking whether the url is correct in Release mode.

如果我们想测试这种行为,我们必须将测试目标的 Build configuartion 标志设置为 Release.

If we want to test for this behavior, we'll have to set the Build configuartion flag to Release for the Test target.

设置为Release时,Xcode编译报错:

When setting it to Release, Xcode compiles for error:

模块 XXXXFramework 未编译用于测试

为了解决这个问题,我们可以简单地将ReleaseEnable Testability设置为我们框架的Yes.

To solve this problem, we can just simply set Enable Testability for Release to Yes for our framework.

但是,问题是 Apple 不建议根据此

However, the issue is that Apple does not recommend setting Enable Testability to Yes for Release mode according to this note

可测试性:编写了 Swift 2.0 框架和应用程序的测试无需公开内部程序.使用@testable 导入{ModuleName} 在您的测试源代码中使所有公开和内部可用的例程.应用程序或框架目标需要编译启用可测试性构建设置设置为是.使能可测试性构建设置应仅在您的调试中使用配置,因为它禁止依赖于不的优化从应用程序或框架导出内部符号.(17732115)

是否有人对解决我的问题有任何建议,或者是否有其他解决方案来实现我的目标?

Does anyone have suggestions for solving my problem, or, any alternative solutions to achieve my goal?

用于使用发布模式测试框架

For testing a framework using Release mode

推荐答案

我为您创建了一个示例项目.您的设置可能有所不同,但此示例项目将演示如何测试发布 url 和调试 url,通过编辑方案设置.这是链接 https://github.com/borg666/ios-multi-方案配置示例

I created a sample project for you. Your setup might be different, but this sample project will demonstrate how to test the release url and debug url, go through the edit scheme settings. Here is the link https://github.com/borg666/ios-multi-scheme-config-example

基本上,诀窍是使用另一个方案,在该方案中禁用调试标志并运行一个单独的测试文件,您可以在其中测试发布 url,通过这样做,您可以自由地启用此方案的可测试性.

Basically the trick is to have another scheme in which debug flag is disabled and it runs a separate test file where you can test the release url, By doing this you are free to enable testability on this scheme.

您可以考虑为 url 使用用户定义的变量,在我的示例中,您可以实现更复杂的配置.

You might consider having user defined variable for the url, with my example you can achieve more complex configurations.

这篇关于如何在发布模式下启用框架的可测试性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:30