fastlane-plugin-instrumented_tests 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +60 -0
- data/lib/fastlane/plugin/instrumented_tests.rb +16 -0
- data/lib/fastlane/plugin/instrumented_tests/actions/instrumented_tests_action.rb +153 -0
- data/lib/fastlane/plugin/instrumented_tests/helper/instrumented_tests_helper.rb +12 -0
- data/lib/fastlane/plugin/instrumented_tests/version.rb +5 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 31b360d1f17a6faaee098e20bff2d1dbea23f8ae
|
4
|
+
data.tar.gz: 0f516c84dfa5a5008259064533f70d1d9f07886e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d12292168548763b03e6e8a3f94f2e7a78af77e242eb5506c6a7e2d7d693eb6b4b5ab34c712ca9d374ff7b9b21c7f6d86c55e1c9d50982c00d2cad5edef649f2
|
7
|
+
data.tar.gz: 4663d7c996f1bed6f73529036de6aa56dcc48ab7be5bc7a541dc39d5730e09933f76acd44ec0839be0764496228b7fd7bd8d6839af171039a4ee6d2236f5926f
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Silviu Paragina <silviu.paragina@mready.net>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# instrumented_tests plugin
|
2
|
+
|
3
|
+
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-instrumented_tests)
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-instrumented_tests`, add it to your project by running:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
fastlane add_plugin instrumented_tests
|
11
|
+
```
|
12
|
+
|
13
|
+
## About instrumented_tests
|
14
|
+
|
15
|
+
Run instrumented tests for android.
|
16
|
+
|
17
|
+
This basically creates and boots an emulator before running an gradle commands so that you can run instrumented tests against that emulator. After the gradle command is executed, the avd gets shut down and deleted. This is really helpful on CI services, keeping them clean and always having a fresh avd for testing.
|
18
|
+
|
19
|
+
## Example
|
20
|
+
|
21
|
+
Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
|
22
|
+
|
23
|
+
Creates and boots avd device before running gradle command.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
instrumented_tests(
|
27
|
+
avd_name: "Nexus_10",
|
28
|
+
target_id: "2",
|
29
|
+
task: "cleanTest createMockDebugCoverageReport --continue",
|
30
|
+
)
|
31
|
+
```
|
32
|
+
|
33
|
+
## Run tests for this plugin
|
34
|
+
|
35
|
+
To run both the tests, and code style validation, run
|
36
|
+
|
37
|
+
````
|
38
|
+
rake
|
39
|
+
```
|
40
|
+
|
41
|
+
To automatically fix many of the styling issues, use
|
42
|
+
```
|
43
|
+
rubocop -a
|
44
|
+
```
|
45
|
+
|
46
|
+
## Issues and Feedback
|
47
|
+
|
48
|
+
For any other issues and feedback about this plugin, please submit it to this repository.
|
49
|
+
|
50
|
+
## Troubleshooting
|
51
|
+
|
52
|
+
If you have trouble using plugins, check out the [Plugins Troubleshooting](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/PluginsTroubleshooting.md) doc in the main `fastlane` repo.
|
53
|
+
|
54
|
+
## Using `fastlane` Plugins
|
55
|
+
|
56
|
+
For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Plugins.md).
|
57
|
+
|
58
|
+
## About `fastlane`
|
59
|
+
|
60
|
+
`fastlane` is the easiest way to automate building and releasing your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fastlane/plugin/instrumented_tests/version'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module InstrumentedTests
|
5
|
+
# Return all .rb files inside the "actions" and "helper" directory
|
6
|
+
def self.all_classes
|
7
|
+
Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# By default we want to import all available actions and helpers
|
13
|
+
# A plugin can contain any number of actions and plugins
|
14
|
+
Fastlane::InstrumentedTests.all_classes.each do |current|
|
15
|
+
require current
|
16
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
module SharedValues
|
7
|
+
end
|
8
|
+
|
9
|
+
class InstrumentedTestsAction < Action
|
10
|
+
def self.run(params)
|
11
|
+
gradle = Helper::GradleHelper.new(gradle_path: Dir["./gradlew"].last)
|
12
|
+
file = Tempfile.new('emulator_output')
|
13
|
+
|
14
|
+
# Set up params
|
15
|
+
avd_name = "--name \"#{params[:avd_name]}\""
|
16
|
+
target_id = "--target #{params[:target_id]}"
|
17
|
+
avd_options = params[:avd_options] unless params[:avd_options].nil?
|
18
|
+
avd_abi = "--abi #{params[:avd_abi]}" unless params[:avd_abi].nil?
|
19
|
+
avd_tag = "--tag #{params[:avd_tag]}" unless params[:avd_tag].nil?
|
20
|
+
create_avd = ["#{params[:sdk_path]}/tools/android", "create avd", avd_name, target_id, avd_abi, avd_tag, avd_options].join(" ")
|
21
|
+
start_avd = ["#{params[:sdk_path]}/tools/emulator", "-avd #{params[:avd_name]}", "-gpu on -no-boot-anim &>#{file.path} &"]
|
22
|
+
devices = `#{params[:sdk_path]}/tools/android list avd`.chomp
|
23
|
+
|
24
|
+
# Delete avd if one already exists for clean state.
|
25
|
+
unless devices.match(/#{params[:avd_name]}/).nil?
|
26
|
+
Action.sh("#{params[:sdk_path]}/tools/android delete avd -n #{params[:avd_name]}")
|
27
|
+
end
|
28
|
+
|
29
|
+
Helper.log.info("Creating AVD...".yellow)
|
30
|
+
Action.sh(create_avd)
|
31
|
+
|
32
|
+
Helper.log.info("Starting AVD....".yellow)
|
33
|
+
begin
|
34
|
+
Action.sh(start_avd)
|
35
|
+
|
36
|
+
# Wait for device to be fully
|
37
|
+
boot_emulator
|
38
|
+
|
39
|
+
Helper.log.info("Executing gradle command...".green)
|
40
|
+
begin
|
41
|
+
gradle.trigger(task: params[:task], flags: params[:flags], serial: nil)
|
42
|
+
ensure
|
43
|
+
stop_emulator
|
44
|
+
end
|
45
|
+
ensure
|
46
|
+
file.close
|
47
|
+
file.unlink
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.boot_emulator
|
52
|
+
Helper.log.info("Waiting for emulator to finish booting.....".yellow)
|
53
|
+
loop do
|
54
|
+
stdout, _stdeerr, _status = Open3.capture3("#{params[:sdk_path]}/platform-tools/adb shell getprop sys.boot_completed")
|
55
|
+
|
56
|
+
if stdout.strip == "1"
|
57
|
+
Helper.log.info("Emulator Booted!".green)
|
58
|
+
break
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.stop_emulator
|
64
|
+
adb = Helper::AdbHelper.new(adb_path: "#{params[:sdk_path]}/platform-tools/adb")
|
65
|
+
temp = File.open(file.path).read
|
66
|
+
port = temp.match(/console on port (\d+),/)
|
67
|
+
|
68
|
+
if port
|
69
|
+
port = port[1]
|
70
|
+
else
|
71
|
+
Helper.log.info("Could not find emulator port number, using default port.".yellow)
|
72
|
+
port = "5554"
|
73
|
+
end
|
74
|
+
|
75
|
+
Helper.log.info("Shutting down emulator...".green)
|
76
|
+
adb.trigger(command: "emu kill", serial: "emulator-#{port}")
|
77
|
+
|
78
|
+
Helper.log.info("Deleting emulator....".green)
|
79
|
+
Action.sh("#{params[:sdk_path]}/tools/android delete avd -n #{params[:avd_name]}")
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.description
|
83
|
+
"Run android instrumented tests via a gradle command againts a newly created avd"
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.details
|
87
|
+
[
|
88
|
+
"Instrumented tests need a emulator or real device to execute against.",
|
89
|
+
"This action will check for a specific avd and created, wait for full boot,",
|
90
|
+
"run gradle command, then deleted that avd on each run."
|
91
|
+
].join("\n")
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.available_options
|
95
|
+
[
|
96
|
+
FastlaneCore::ConfigItem.new(key: :avd_name,
|
97
|
+
env_name: "AVD_NAME",
|
98
|
+
description: "Name of the avd to be created",
|
99
|
+
is_string: true,
|
100
|
+
optional: false),
|
101
|
+
FastlaneCore::ConfigItem.new(key: :target_id,
|
102
|
+
env_name: "TARGET_ID",
|
103
|
+
description: "Target id of the avd to be created, get list of installed target by running command 'android list targets'",
|
104
|
+
is_string: true,
|
105
|
+
optional: false),
|
106
|
+
FastlaneCore::ConfigItem.new(key: :avd_options,
|
107
|
+
env_name: "AVD_OPTIONS",
|
108
|
+
description: "Other avd options in the form of a <option>=<value> list, i.e \"--scale 96dpi --dpi-device 160\"",
|
109
|
+
is_string: true,
|
110
|
+
optional: true),
|
111
|
+
FastlaneCore::ConfigItem.new(key: :avd_abi,
|
112
|
+
env_name: "AVD_ABI",
|
113
|
+
description: "The ABI to use for the AVD. The default is to auto-select the ABI if the platform has only one ABI for its system images",
|
114
|
+
is_string: true,
|
115
|
+
optional: true),
|
116
|
+
FastlaneCore::ConfigItem.new(key: :avd_tag,
|
117
|
+
env_name: "AVD_TAG",
|
118
|
+
description: "The sys-img tag to use for the AVD. The default is to auto-select if the platform has only one tag for its system images",
|
119
|
+
is_string: true,
|
120
|
+
optional: true),
|
121
|
+
FastlaneCore::ConfigItem.new(key: :sdk_path,
|
122
|
+
env_name: "SDK_PATH",
|
123
|
+
description: "The path to your android sdk directory",
|
124
|
+
is_string: true,
|
125
|
+
default_value: ENV['SDK_PATH'],
|
126
|
+
optional: true),
|
127
|
+
FastlaneCore::ConfigItem.new(key: :flags,
|
128
|
+
env_name: "GRADLE_FLAGS",
|
129
|
+
description: "All parameter flags you want to pass to the gradle command, e.g. `--exitcode --xml file.xml`",
|
130
|
+
optional: true,
|
131
|
+
is_string: true),
|
132
|
+
FastlaneCore::ConfigItem.new(key: :task,
|
133
|
+
env_name: "GRADLE_TASK",
|
134
|
+
description: "The gradle task you want to execute",
|
135
|
+
is_string: true,
|
136
|
+
optional: false)
|
137
|
+
]
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.return_value
|
141
|
+
"The output from the test execution."
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.authors
|
145
|
+
["joshrlesch"]
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.is_supported?(platform)
|
149
|
+
platform == :android
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fastlane
|
2
|
+
module Helper
|
3
|
+
class InstrumentedTestsHelper
|
4
|
+
# class methods that you define here become available in your action
|
5
|
+
# as `Helper::InstrumentedTestsHelper.your_method`
|
6
|
+
#
|
7
|
+
def self.show_message
|
8
|
+
UI.message("Hello from the instrumented_tests plugin helper!")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fastlane-plugin-instrumented_tests
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Silviu Paragina
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fastlane
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.96.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.96.0
|
97
|
+
description:
|
98
|
+
email: silviu.paragina@mready.net
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- lib/fastlane/plugin/instrumented_tests/actions/instrumented_tests_action.rb
|
104
|
+
- lib/fastlane/plugin/instrumented_tests/helper/instrumented_tests_helper.rb
|
105
|
+
- lib/fastlane/plugin/instrumented_tests/version.rb
|
106
|
+
- lib/fastlane/plugin/instrumented_tests.rb
|
107
|
+
- README.md
|
108
|
+
- LICENSE
|
109
|
+
homepage:
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.0.14.1
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: New action to run instrumented tests for android. This basically creates
|
133
|
+
and boots an emulator before running an gradle commands so that you can run instrumented
|
134
|
+
tests against that emulator. After the gradle command is executed, the avd gets
|
135
|
+
shut down and deleted. This is really helpful on CI services, keeping them clean
|
136
|
+
and always having a fresh avd for testing.
|
137
|
+
test_files: []
|