iOS 开发自动化测试/CI测试

Fastlane 使用

2017-12-03  本文已影响9人  陳文豪

一. 官网:Fastlane  

二. 安装:

1.先安装 Xcode command line tools

           若提示:command line tools are already installed, use "Software Update" to install updates,  则表示已经安装过了。

$ xcode-select --install

2.安装fastlane。

$ sudo gem install fastlane

三. 使用:

1. 初始化 fastlane

    cd到你项目根目录,输入

$ fastlane init

$ fastlane init

[14:51:32]:Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile

[14:51:35]: Detected iOS/Mac project in current directory...

[14:51:35]:This setup will help you get up and running in no time.

[14:51:35]:fastlane will check what tools you're already using and set up

[14:51:35]:the tool automatically for you. Have fun!

[14:51:35]:Created new folder './fastlane'.

[14:51:35]:$ xcodebuild -list -workspace ./xxxx.xcworkspace

Select Scheme:

    这时候会先列出一堆 scheme 让你选择,我们根据需要选择就好。接下来会让你输入你的 Apple ID 和密码

[14:55:22]:Your Apple ID (e.g. fastlane@krausefx.com):

Password (for xxxxx@xxx.com):

完成后 fastlane 会在目录下创建名为 fastlane 的文件夹,包含

fastlane文件夹

   Appfile 中主要存储你的 app_identifier、apple_id和team_id等信息的,里面长这样

app_identifier "com.xxxx.xxxx" # The bundle identifier of your app

apple_id "xxxxx@xxx.com" # Your Apple email address

team_id "xxxxxx" # Developer Portal Team ID

# you can even provide different app identifiers, Apple IDs and team names per lane:

# More information: https://docs.fastlane.tools/advanced/#appfile

再有就是 Fastfile , 它是用来管理 lane 的,每一个 lane 相当于一个任务。初始化后里面已经默认生成 “beta” 和“release”  的 lane ,用于打包测试环境和app store的ipa的。要执行对应的lane,只需在终端cd到项目的根目录:执行fastlane lane'name就可ok了。

2. 用 fastlane 打包app并上传到蒲公英

2.1 安装蒲公英的 Fastlane 插件。

    在终端中,cd 到项目根目录,输入以下命令,即可安装蒲公英的 fastlane 插件。这里会有个坑,需要切换到项目根目录下,不能直接全局安装,具体原因还没有研究,知道的童鞋望告知一下。

fastlane add_plugin pgyer

2.2. 配置蒲公英参数

    插件安装成功后,去修改 Fastfile 里面的 beta 任务,配置一下蒲公英的参数:

lane :beta do

gym(scheme:"你的scheme",

workspace: "你的xcworkspace名称.xcworkspace",

export_method: "ad-hoc")  #这里测试包选择ad-hoc

pgyer(api_key: "蒲公英申请的 api_key",

user_key: "蒲公英申请的 user_key",

update_description: “beta”)  #更新日志

end

     其中gym 是针对于 iOS 编译打包生成 ipa 文件的命令。还有一些其他的命令如: 

match 同步团队每个人的证书和 Provision file 的工具

deliver 用于上传应用的二进制代码,应用截屏和元数据到 App Store

scan 自动化测试工具,很好的封装了 Unit Test

sigh 针对于 iOS 项目开发证书和 Provision file 的下载工具

snapshot 可以自动化iOS应用在每个设备上的本地化截屏过程

    配置完成后,则可以测试下试效果如何,使用:

fastlane beta

    稍等一会,就可以看到成功的信息了。当然 fastlane 的强大不止这一点点。

上一篇下一篇

猜你喜欢

热点阅读