在发布版本期间运行 Xcode 单元测试 [英] Running Xcode unit tests during release build

查看:29
本文介绍了在发布版本期间运行 Xcode 单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多逻辑单元测试(其中我的项目文件具有 App 和 AppTests 的目标成员资格).我想向我的构建系统添加对 xcodebuild test-without-building 的调用,以便我的单元测试针对每个构建运行.

I have a number of logic unit-tests (where my project files have a target membership of the App and AppTests). I want to add a call to xcodebuild test-without-building to my build system so that my unit-tests run for each build.

但是,测试不能在发布版本上运行(因为发布版本不是为测试而构建的).

However, the tests cannot run on the release build (because release doesn't build for testing).

我是否只能选择在构建过程中同时构建发布版本调试版本,以便我只能使用调试版本来执行测试?这与我使用过的其他测试框架(GTest、Catch)非常不同,而且非常糟糕.为什么测试不能自立?

Is my only choice to build both the release version and the debug version during my build, so that I can use the debug version only to perform the tests? That's very different and very much worse to the other test frameworks I've used (GTest, Catch). Why can't the tests stand on their own?

推荐答案

test-without-building 命令实际上并不是为了运行测试而不重建应用程序",而是应该与 build-for-testing 命令一起使用.

The test-without-building command is not actually meant to "run the tests without rebuilding the app", but rather it's supposed to be used in tandem with the build-for-testing command.

请参阅 高级测试和持续集成"WWDC 2016 会议 了解更多信息.

Please refer to the "Advanced Testing and Continuous Integration" WWDC 2016 session for more info.

要点是:使用 build-for-testing 构建一个 .xctestrun 文件,然后由 test-without-building 使用> 运行测试.这对于在不同机器上运行大型套件特别有用,尽管我自己从未这样做过.

The gist is: use build-for-testing to build an .xctestrun file, which is then used by test-without-building to run the tests. This is particularly useful to run big suites across different machines, although I have never done it myself.

既然我们已经确定您不能单独使用 test-without-building,这是从命令行运行测试的唯一选项,如果它们通过构建 Release 版本是使用 xcodebuild test 来构建应用程序.

Now that we have established that you can't use test-without-building on its own, the only option to run the test from the command line and if they pass build a Release version is to use xcodebuild test, which is going to build the app.

至于为什么需要在Debug中,我没有确切的答案.在 iOS 领域,至少在我合作过的团队中,DebugRelease 构建之间的区别始终仅在于传递给编译器的优化选项之类的东西、要构建的架构以及代码签名的类型.

As for the why does it need to be in Debug, I don't have a precise answer. In iOS land, at least in the teams I worked with, the difference between Debug and Release builds is always only on things like the options passed to the compiler in terms of optimization, the architectures to build on, and the type of code signing.

这意味着在 DebugRelease 中运行的代码完全相同,而且由于我们已经确定您需要构建应用程序两次,一次要运行测试,生成可发布版本,在 Debug 中运行测试似乎可以接受.

This means that the code that runs in Debug vs Release is exactly the same, and since we already established that you'll need to build the app twice, one to run the tests, one to generate the releasable version, running the tests in Debug seems acceptable.

这篇关于在发布版本期间运行 Xcode 单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆