0%

测试及持续集成

现如今鉴于环境的问题,work from home 的职缺多了起来,软件开发中的 wfh 需要的特别技能就显现出来了。

  • unit test 单元测试
  • code Coverage 代码覆盖率
  • Continuous Integration CI 持续集成
  1. 测试
    1. 并行执行 uitest
    2. 不要每次测试连uitest也一起执行
    3. 每个测试文件都添加到测试target是不是太费事
  2. 持续集成
    1. 2021-06-17目前 circle ci 只支持 Fastlane Match 的方式管理 code sign
  3. 问题
    1. code coverage report
    2. circleci 正则
    3. circleci cache
    4. ci 环境里部署 error: Missing private key for signing certificate. Failed to locate the private key matching certificate "xxxx" in the keychain.
    5. @testable import objective c
  4. 参考
    1. unit test
    2. ci & cd

测试

并行执行 uitest

找了下方法还是比较容易操作的,但是ci上可能不容易要试过。Parallelizing UI Tests for iOS Applications

不要每次测试连uitest也一起执行

在 scheme 里 test → info → 勾掉 ui test

每个测试文件都添加到测试target是不是太费事

When you create a Unit Testing Bundle(Unit Testing target) for testing application you have two options:

  1. Enable Allow testing Host Application APIs
    General -> Host Application <app_name>-> >check< Allow testing Host Application APIs

    • slow build
  2. Add every app’s tested file into Target Membership

    • you should take care of classes dependencies which are used into testable class(they should be added too)

When you write a test and no one option was not enabled you can get

Undefined symbol: nominal type descriptor for <class_name>
Undefined symbol: type metadata accessor for<class_name></class_name></class_name></app_name>

持续集成

2021-06-17目前 circle ci 只支持 Fastlane Match 的方式管理 code sign

Note: CircleCI only officially supports Fastlane Match for codesigning. Other methods may be used, but are not guaranteed to work and are unsupported.

问题

code coverage report

测试报告,尤其是含有代码覆盖率的报告,如何在ci的环境里也能生成。

slather
这个貌似用的人最多,但是调试了半天,本地都跑不起来。错误一般都是类似这种 "find_binary_files": No product binary found,最后也没找到解决办法。

xcov
因为 slather 的失败,转而找到了这个方式
很快的本地直接就跑好了,大喜感觉靠谱多了,但是跑到 ci 环境里确出现了一个恼人的问题 ould not find option 'workspace' in the list of available options:,很难查到原因,又耽误了半天。
开始升级了 fastlane 试试看,不行;最后也是试出了解决方法也就是 bundle update,也是,也就是环境的问题了。

CircleCI 2.0 + fastlane + Slather でコードカバレッジの変化を Slack に通知する

circleci 正则

circleci 提供了一种区分branch的方法,可以用来区分branch来做任务

workflows:
version: 2
build_to_testflight:
jobs:
- buildDevelop: # only for develope branch
filters: # using regex filters requires the entire branch to match
branches:
only: /^[^0-9]*/ # only branches matching the below regex filters will run
- buildBeta: # for release branch
filters: # using regex filters requires the entire branch to match
branches:
only: /^[0-9]*/
- buildProduct: # for release branch
filters: # using regex filters requires the entire branch to match
branches:
only: /^[0-9]*/

java.util.regex Class Pattern
Using Workflows to Schedule Jobs

circleci cache

用了cache后,出现了很多问题,基本上都是环境没有准备好导致的。
可以先用 brew doctor 看看问题
然后我这里是需要 brew link 相关的 package
然后 brew link a b c 基本上就可以了

# cache brew install
- restore_cache:
keys:
- homebrew-v1
- run:
name: cache check for package stuff & install/setup if not cached
command: |
brew update
# 处理icon图片相关
[ ! -d /usr/local/Cellar/librsvg ] && brew install librsvg && echo "done installing librsvg"
[ ! -d /usr/local/Cellar/imagemagick ] && brew install imagemagick && echo "done installing imagemagick"
# 此目录并没有保存
# ls -al /usr/local/opt
ls -al /usr/local/Cellar/imagemagick
ls -al /usr/local/Cellar/librsvg
echo $PATH
echo $BASH_ENV
echo 'export PATH="/usr/local/Cellar/imagemagick/7.1.0-2_1/bin:$PATH"' >> $BASH_ENV
echo 'export PATH="/usr/local/Cellar/librsvg/2.50.7/bin:$PATH"' >> $BASH_ENV
echo $SHELL
echo $PATH
echo $BASH_ENV
source $BASH_ENV
# rsvg-convert -v
# magick -version
brew cleanup
- save_cache:
key: homebrew-v1
paths:
- /Users/distiller/Library/Caches/Homebrew #shorten brew update
- /usr/local/Homebrew #shorten brew update
- /usr/local/opt
- /usr/local/Cellar #shorten brew install

ci 环境里部署 error: Missing private key for signing certificate. Failed to locate the private key matching certificate "xxxx" in the keychain.

这个问题已经持续了大半天了,不知道还要多久解决,感觉定位到了 keychain 上,但还没搞定哈。
终于还是解决 Manually manage the fastlane match Repo ,还是官方的文档靠谱。

先保存下有用的连接:
Manually manage the fastlane match Repo
Github actions + Fastlane + iOS = ❤
iOS Continuous Deployment with Fastlane 🚀
macos keychain access

@testable import objective c

在 swift 里可以直接集成 main target 所有的方法,这样就不用一个个将要测试的文件勾选到测试 target 里了,当然这种方式方便了,就是build速度上会有影响。
但是如果是 oc 项目没有 @testable 关键字使用的话,应该怎么弄?
这里给出了答案 When do app sources need to be included in test targets?

参考

unit test

How to make your unit tests run faster

ci & cd

iOS Continuous Deployment Using Travis CI and Fastlane
使用fastlane match自动和手动管理证书
Build and Deploy your iOS app with Github Actions and Fastlane
iOS CI/CD with GitHub Actions
iOS TestFlight Deploy With GitHub Actions
苹果开发最便捷的持续集成方案—Xcode Server
CircleCI Vs. GitLab: Choosing The Right CI/CD Tool并且这图表也太好看了
migrate to circleci 2.0 in iOS with fastlane
Fastlane/Jenkins:一人團隊也用得上的 Continuous Delivery 系統
代码覆盖率 (Code Coverage)从简到繁 (一)