Lane: run_unit_tests

Description

It's a good practice to write test for your code. So, before create a new build and share it for someone you must check that your tests are 'green'. This lane can helps you with this.

It uses run_testsopen in new window (old scanopen in new window) with makes it easy to run tests of your iOS app on a simulator or connected device. It also uses xcovopen in new window witch analyzes the .xccoverage files created after running your tests. Herefore, before executing xcovopen in new window, you need to run your tests with run_testsopen in new window.

And it looks very great in your slack channel. 💪

Screenshot

Overview

lane :run_unit_tests do |options|

  scheme = options[:scheme] || @scheme
  target = options[:target]

  sh 'rm -rf ../tests'
  sh 'mkdir -p ../tests'

  run_tests(
    skip_build: true,
    clean: false,
    device: 'iPhone 8',
    scheme: scheme,
    fail_build: true,
    code_coverage: true,
    output_directory: "./tests",
    output_types: "html,junit,json-compilation-database",
    slack_url: "https://hooks.slack.com/services/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",
    slack_channel: "ios_builds"
  )

  xcov(
    workspace: "Unight.xcworkspace",
    scheme: scheme,
    output_directory: "./tests/xcov",
    slack_url: "https://hooks.slack.com/services/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",
    slack_channel: "ios_builds",
    include_targets: "#{target}.app",
    html_report: true,
    markdown_report: true,
    json_report: true
  )

end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

Usage

Update your Fastfile to contain the following code:

...

build(
  app_store: false,
  app_name: @app_name,
  scheme: @scheme,
  clean: false,
  build_number_additional_string: "#{server_env}"
)

run_unit_tests(
  scheme: @scheme,
  target: 'Fitcheck'
)

deliver_to_crashlytics

...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Lane Parameters

KeyDescription
schemeThe project's scheme. Make sure it's marked as Shared. Defaults to @scheme
targetThe name of the target.

Notes

  • It is important to add lane run_tests after build but before deliver_to_crashlytics or deliver_to_testflight
  • How to get slack_url and slack_channel you can read here