加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 如何让Travis CI构建和测试Github上托管的xcode

发布时间:2020-12-14 20:02:29 所属栏目:百科 来源:网络整理
导读:我在 github上托管了一些开源代码,用于添加 block based category to UITextField.我添加了一个.travis.yml文件,以便让travis CI在每次推送时构建和运行代码. Link to The Travis CI warning .它成功地建立了这个项目. 运行.travis.yml脚本时收到的警告是:
我在 github上托管了一些开源代码,用于添加 block based category to UITextField.我添加了一个.travis.yml文件,以便让travis CI在每次推送时构建和运行代码. Link to The Travis CI warning .它成功地建立了这个项目.
运行.travis.yml脚本时收到的警告是:

WARNING: Using Objective-C testing without specifying a scheme and either
a workspace or a project is deprecated.

我想运行的示例项目位于文件夹/ UITextView Blocks Example /
如何添加到.travis.yml文件来运行此项目?
我的travis.yml文件现在由

language: objective-c

解决方法

2017年更新

skypecakes提及in the comments:

For anyone using XCode 8 and higher: xctool is no longer supported,and does not work.
Use 07002 instead.

原始答案(2013)

你可以查看this tutorial,其解释如下:

xctool is an excellent choice for running your tests under a continuous integration server such as Travis CI or Jenkins.
In order to your run your tests within a continuous integration environment,you must create Shared Schemes for your application target and ensure that all dependencies (such as CocoaPods) are added explicitly to the Scheme.
To do so:

  1. Open up the Manage Schemes sheet by selecting the Product menu > Schemes > Manage Schemes…
  2. Locate your application target in the list. Ensure that the Shared checkbox in far right hand column of the sheet is checked.
  3. If your application or test targets include cross-project dependencies such as CocoaPods,then you will need to ensure that they have been configured as explicit dependencies. To do so:
    • Highlight your application target and hit the Edit… button to open the Scheme editing sheet.
    • Click the Build tab in the left-hand panel of the Scheme editor.
    • Click the + button and add each dependency to the project. CocoaPods will appears as static library named Pods.
    • Drag the dependency above your application target so that it is built first.

You will now have a new file in the xcshareddata/xcschemes directory underneath your Xcode project.
This is the shared Scheme that you just configured.
Check this file into your repository and xctool will be able to find and execute your tests on the next CI build.

For more flexibility,you can also control how Travis installs and invokes xctool:

language: objective-c
before_install:
    - brew update
    - brew install xctool
script: xctool -workspace MyApp.xcworkspace -scheme MyApp test

最后一个配置类似于this other tutorial中说明的方法:

Once you have linked your repo the next step would be to add a .travis.yml file to the root of the repo.

language: objective-c

  before_script: travis/before_script.sh
  script: travis/script.sh
  • First I’m telling Travis that this is an objective-c project.
  • Next I tell Travis how I’d like it to do CI against this repo by giving it instructions on what scripts it should run in order to actually perform a build.

I also give some extra instructions on what to do just prior to running a build.
It’s quite common to put all the build steps inline right in the .travis.yml file,but I prefer to actually create bash scripts in my repo inside a travis directory in my git repo and then just refer to those scripts from my .travis.yml.
This keeps the .yml file nice and small,and also makes it easy for me to test the travis build scripts locally.

We gave Travis a before_script in the .yml file above. This is intended to be used by the Travis agent to download tools needed as part of the build. Here’s what it looks like:

travis/before_script.sh

#!/bin/sh
set -e

brew update
brew install xctool

Very simple. We just use homebrew to install xctool on the build agent.
All travis build agents come with homebrew pre-installed,but sometimes the formula aren’t up to date,so it’s best to run a brew update before attempting a brew install.
That’s all we need to do to prepare our agent for the build.

Next let’s look at the build script itself:

travis/script.sh

#!/bin/sh
set -e

xctool -workspace MyWorkspace -scheme MyScheme build test

Again,this is really simple.
We first do a basic sanity check by asking xctool to build our app,specifying a workspace and scheme.
This just checks that we don’t have any compilation errors.
Assuming that succeeds xctool will then build and run the unit testing target for our app,launching the Simulator on the Travis agent if needed.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读