iOS相关

结合fastlane 组件进行自动化测试

2019-02-24  本文已影响9人  不伟心

1.Xcode创建一个含有Unit Tests的项目
1)单元测试target设置
info中添加tests,options中勾选Gather coverage框。xcode9.2和xcode9.3位置不太一样,下面的图片是xcode9.3的配置 这个是测覆盖率用的
2.安装fastlane
1)sudo gem install fastlane -NV或是brew cask install fastlane我这里使用gem安装的
2)安装完了执行fastlane --version,确认下是否安装完成和当前使用的版本号。、3.初始化Fastlane
1)cd到你的项目目录执行
2)fastlane init
初始化成功后会在当前工程目录生成一个fastlane文件夹
Appfile主要存放App的apple_id team_id app_identifier等信息
Deliverfile中为发布的配置信息,一般情况用不到。
Fastfile是我们最应该关注的文件,也是我们的工作文件。

  1. 添加组件
    fastlane add_plugin xcpretty_report 用于生成测试报告
    5)配置Fastfile相关信息
default_platform(:ios)

platform :ios do

  desc "自动化测试"

  lane :unittest do 
    UI.message("start  xcodebuild")
    xcodebuild(
      test: true,
      scheme: "quickDemo",
      workspace: "quickDemo.xcworkspace",
      destination: "platform=iOS Simulator,name=iPhone XR,OS=12.1",
    )
    UI.message("success  xcodebuild")

    xcpretty_report(
        buildlog_path: 'fastlane',
        output_path: 'fastlane/reports',
        use_json_formatter: true
    )  
    # gym(
      #   xcpretty_report_html:"tests.html",
    # )
    UI.message("start  xcov")
    xcov(
      scheme: "quickDemo",
      workspace: "quickDemo.xcworkspace",
      html_report: "true",
      json_report: "true",
      output_directory:"quickDemoesss"
    )
    UI.message("success  xcov")

    desc "读取覆盖率"
    file = File.read(File.expand_path("/Users/edz/Desktop/quickDemo/quickDemoesss/report.json"))
    if file
        data = JSON.parse(file)
        UI.message(data)
        UI.message(data["coverage"])
   else
      UI.error("Unable to open file!")
      return
   end
  end

end

6 执行 fastlane unittest

上一篇 下一篇

猜你喜欢

热点阅读