├── settings.gradle ├── CHANGELOG.md ├── demo ├── composer.gif ├── screenshot1.png ├── screenshot2.png └── screenshot3.png ├── html-report ├── layout │ ├── log-entry.html │ ├── log-container.html │ └── index.html ├── .babelrc ├── styles │ ├── helpers │ │ ├── index.scss │ │ ├── _variables.scss │ │ ├── _mixins.scss │ │ ├── _colors.scss │ │ └── _fonts.scss │ ├── index.scss │ ├── _base.scss │ ├── _components.scss │ ├── _custom.scss │ ├── _layout.scss │ ├── _form.scss │ └── _elements.scss ├── webpack.config.js ├── src │ ├── index.js │ ├── utils │ │ ├── paths.js │ │ └── convertTime.js │ ├── App.js │ └── components │ │ ├── Suite.js │ │ ├── SuitesList.js │ │ ├── TestItem.js │ │ └── SearchBar.js ├── webpack.config.dev.js ├── postcss.config.js ├── webpack.config.prod.js └── package.json ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── composer ├── src │ ├── test │ │ ├── resources │ │ │ ├── instrumentation-test.apk │ │ │ ├── instrumentation-output-0-tests.txt │ │ │ ├── instrumentation-output-app-crash.txt │ │ │ ├── instrumentation-output-unable-to-find-instrumentation-info.txt │ │ │ ├── instrumentation-output-ignored-test.txt │ │ │ ├── instrumentation-unordered-output.txt │ │ │ ├── instrumentation-output-assumption-violation.txt │ │ │ └── instrumentation-output-failed-test.txt │ │ └── kotlin │ │ │ └── com │ │ │ └── gojuno │ │ │ └── composer │ │ │ ├── test.kt │ │ │ ├── html │ │ │ ├── HtmlDeviceSpec.kt │ │ │ ├── HtmlShortTestSpec.kt │ │ │ ├── HtmlFullTestSpec.kt │ │ │ ├── HtmlFullSuiteSpec.kt │ │ │ └── HtmlShortSuiteSpec.kt │ │ │ ├── ApkSpec.kt │ │ │ ├── LogLineParserSpec.kt │ │ │ ├── JUnitReportSpec.kt │ │ │ └── ArgsSpec.kt │ └── main │ │ └── kotlin │ │ └── com │ │ └── gojuno │ │ └── composer │ │ ├── TestMethod.kt │ │ ├── html │ │ ├── HtmlIndex.kt │ │ ├── HtmlDevice.kt │ │ ├── HtmlShortSuite.kt │ │ ├── HtmlShortTest.kt │ │ ├── HtmlFullSuite.kt │ │ ├── HtmlFullTest.kt │ │ └── HtmlReport.kt │ │ ├── Files.kt │ │ ├── Apk.kt │ │ ├── JUnitReport.kt │ │ ├── Args.kt │ │ ├── Instrumentation.kt │ │ ├── TestRun.kt │ │ └── Main.kt └── build.gradle ├── .travis.yml ├── .gitignore ├── ci ├── docker │ ├── entrypoint.sh │ └── Dockerfile └── build.sh ├── dependencies.gradle ├── gradlew.bat ├── spec └── REPORT.md ├── gradlew ├── README.md └── LICENSE.txt /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':composer' 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # See [Releases](https://github.com/gojuno/composer/releases) 2 | -------------------------------------------------------------------------------- /demo/composer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gojuno/composer/HEAD/demo/composer.gif -------------------------------------------------------------------------------- /demo/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gojuno/composer/HEAD/demo/screenshot1.png -------------------------------------------------------------------------------- /demo/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gojuno/composer/HEAD/demo/screenshot2.png -------------------------------------------------------------------------------- /demo/screenshot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gojuno/composer/HEAD/demo/screenshot3.png -------------------------------------------------------------------------------- /html-report/layout/log-entry.html: -------------------------------------------------------------------------------- 1 |
2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gojuno/composer/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /html-report/layout/log-container.html: -------------------------------------------------------------------------------- 1 |{ data.stacktrace }
72 | ` is the last line printed by instrumentation, even if 0 tests were run.
116 | !it.startsWith("INSTRUMENTATION_CODE")
117 | }
118 | .scan(Result()) { previousResult, newLine ->
119 | val buffer = when (previousResult.readyForProcessing) {
120 | true -> newLine
121 | false -> "${previousResult.buffer}${System.lineSeparator()}$newLine"
122 | }
123 |
124 | Result(buffer = buffer, readyForProcessing = newLine.startsWith("INSTRUMENTATION_STATUS_CODE"))
125 | }
126 | .filter { it.readyForProcessing }
127 | .map { it.buffer }
128 | .map(::parseInstrumentationEntry)
129 | }
130 |
131 | fun Observable.asTests(): Observable {
132 | data class Result(val entries: List = emptyList(), val tests: List = emptyList(), val totalTestsCount: Int = 0)
133 |
134 | return this
135 | .scan(Result()) { previousResult, newEntry ->
136 | val entries = previousResult.entries + newEntry
137 | val tests: List = entries
138 | .mapIndexed { index, first ->
139 | val second = entries
140 | .subList(index + 1, entries.size)
141 | .firstOrNull {
142 | first.clazz == it.clazz &&
143 | first.test == it.test &&
144 | first.current == it.current &&
145 | first.statusCode != it.statusCode
146 | }
147 |
148 | if (second == null) null else first to second
149 | }
150 | .filterNotNull()
151 | .map { (first, second) ->
152 | InstrumentationTest(
153 | index = first.current,
154 | total = first.numTests,
155 | className = first.clazz,
156 | testName = first.test,
157 | status = when (second.statusCode) {
158 | StatusCode.Ok -> Passed
159 | StatusCode.Ignored -> Ignored()
160 | StatusCode.AssumptionFailure -> Ignored(stacktrace = second.stack)
161 | StatusCode.Failure -> Failed(stacktrace = second.stack)
162 | StatusCode.Start -> throw IllegalStateException(
163 | "Unexpected status code [Start] in second entry, " +
164 | "please report that to Composer maintainers ($first, $second)"
165 | )
166 | },
167 | durationNanos = second.timestampNanos - first.timestampNanos
168 | )
169 | }
170 |
171 | Result(
172 | entries = entries.filter { entry -> tests.firstOrNull { it.className == entry.clazz && it.testName == entry.test } == null },
173 | tests = tests,
174 | totalTestsCount = previousResult.totalTestsCount + tests.size
175 | )
176 | }
177 | .takeUntil {
178 | if (it.entries.count { it.current == it.numTests } == 2) {
179 | if (it.totalTestsCount < it.entries.first().numTests) {
180 | throw IllegalStateException("Less tests were emitted than Instrumentation reported: $it")
181 | }
182 |
183 | true
184 | } else {
185 | false
186 | }
187 | }
188 | .filter { it.tests.isNotEmpty() }
189 | .flatMap { Observable.from(it.tests) }
190 | }
191 |
--------------------------------------------------------------------------------
/html-report/styles/_elements.scss:
--------------------------------------------------------------------------------
1 | /**
2 | Card block
3 | Card with info
4 | Buttons
5 | Buttons group
6 | Dropdown
7 | Titles
8 | Text elements
9 | Dropdown
10 | Notifications
11 | Tooltip
12 | Title + text block
13 | Labels
14 | Icons
15 | **/
16 |
17 | /* Card */
18 | .card {
19 | margin-bottom: $margin;
20 | padding: $side-padding;
21 | border-radius: 4px;
22 | background: #fff;
23 | box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
24 | }
25 |
26 | @media $large-screen {
27 | .card {
28 | padding: $side-padding-desktop;
29 | }
30 | }
31 |
32 | /* Card with info */
33 |
34 | .card-info {
35 | margin-right: $side-padding;
36 | flex-grow: 1;
37 | }
38 |
39 | .card-info__title {
40 | @extend .text-sub-title-light;
41 | }
42 |
43 | .card-info__content {
44 | margin-top: 15px;
45 | font-size: 40px;
46 | line-height: 1;
47 | color: $electric;
48 | font-weight: 300;
49 | }
50 |
51 | /* Buttons */
52 | $button-inner-shadow: inset 0 2px 1px 0 rgba(0, 0, 0, 0.1);
53 | $button-inner-shadow-darker: inset 0 2px 1px 0 rgba(0, 0, 0, 0.1);
54 | $button-height: 34px;
55 |
56 | .button {
57 | display: inline-block;
58 | box-sizing: border-box;
59 | height: $button-height;
60 | padding: 0 12px;
61 | border-radius: 4px;
62 | border: none;
63 | font-size: $font-normal;
64 | font-weight: 500;
65 | line-height: $button-height;
66 | text-align: center;
67 | background-color: $purple;
68 | color: $white;
69 | outline: none;
70 | cursor: pointer;
71 | transition: background $short-transition;
72 |
73 | &:hover:not(.disabled), &:hover:not([disabled]) {
74 | background-color: $purple-darker;
75 | }
76 |
77 | &:active:not(.disabled), &:active:not([disabled]) {
78 | background-color: $purple-darker;
79 | }
80 |
81 | &:hover {
82 | color: $white;
83 | }
84 |
85 | &.small {
86 | min-width: 80px;
87 | height: 24px;
88 | font-size: $font-small;
89 | padding: 2px 12px 0;
90 | }
91 |
92 | &.full {
93 | width: 100%;
94 | }
95 |
96 | &.fixed {
97 | min-width: 90px;
98 | }
99 |
100 | &.disabled, &[disabled] {
101 | opacity: .5;
102 | cursor: default;
103 | }
104 |
105 | &.flat {
106 | border-radius: 0;
107 | }
108 |
109 | &.success {
110 | background-color: $green;
111 | border-color: $green;
112 | color: $white;
113 |
114 | &:hover:not(.disabled), &:hover:not([disabled]) {
115 | background-color: $green-darker;
116 | }
117 |
118 | &:active:not(.disabled), &:active:not([disabled]) {
119 | background-color: $green-darker;
120 | }
121 | }
122 |
123 | &.alert {
124 | background-color: $red;
125 | color: $white;
126 |
127 | &:hover:not(.disabled), &:hover:not([disabled]) {
128 | background-color: $red-darker;
129 | }
130 |
131 | &:active:not(.disabled), &:active:not([disabled]) {
132 | background-color: $red-darker;
133 | }
134 | }
135 |
136 | &.warning {
137 | background-color: $yellow;
138 | color: $white;
139 |
140 | &:hover:not(.disabled), &:hover:not([disabled]) {
141 | background-color: $yellow-darker;
142 | }
143 |
144 | &:active:not(.disabled), &:active:not([disabled]) {
145 | background-color: $yellow-darker;
146 | }
147 | }
148 |
149 | &.secondary {
150 | background-color: $light-grey;
151 | color: $primary-blue;
152 |
153 | &:hover:not(.disabled), &:hover:not([disabled]) {
154 | background-color: $light-grey-darker;
155 | }
156 |
157 | &:active:not(.disabled), &:active:not([disabled]) {
158 | background-color: $light-grey-darker;
159 | }
160 | }
161 | }
162 |
163 | /* Buttons group */
164 |
165 | .button-group {
166 | .button {
167 | margin-right: 20px;
168 | }
169 | }
170 |
171 | /* Titles */
172 |
173 | .title-common {
174 | margin-bottom: 32px;
175 | @extend .text-title;
176 | }
177 |
178 | .title-common-simple {
179 | @extend .text-title;
180 | text-transform: uppercase;
181 | }
182 |
183 | /* Text elements */
184 |
185 | .emphasized {
186 | @extend .text-sub-title;
187 | }
188 |
189 | .italic {
190 | font-style: italic;
191 | }
192 |
193 | .success,
194 | // deprecated
195 | .successful {
196 | color: $green;
197 | }
198 |
199 | .warning {
200 | color: $yellow;
201 | }
202 |
203 | .danger,
204 | // deprecated
205 | .failure {
206 | color: $red;
207 | }
208 |
209 | .fair {
210 | color: $primary-grey;
211 | }
212 |
213 | .bold {
214 | font-weight: bold;
215 | }
216 |
217 | .align-center {
218 | text-align: center;
219 | }
220 |
221 | .valign {
222 | vertical-align: middle;
223 | }
224 |
225 | .nowrap {
226 | white-space: nowrap;
227 | }
228 |
229 | .break-word {
230 | overflow-wrap: break-word;
231 | word-wrap: break-word;
232 | word-break: break-word;
233 | }
234 |
235 | .small {
236 | @extend .text-note;
237 | color: $primary-grey;
238 | }
239 |
240 | .grey {
241 | color: $primary-grey;
242 | }
243 |
244 | /* Dropdown */
245 |
246 | .dropdown.button {
247 | position: relative;
248 | padding-right: 36px;
249 |
250 | &:after {
251 | content: '';
252 | position: absolute;
253 | display: block;
254 | top: 13px;
255 | right: 16px;
256 | width: 0;
257 | height: 0;
258 | border-top: 4px solid $white;
259 | border-left: 4px solid transparent;
260 | border-right: 4px solid transparent;
261 | }
262 | }
263 |
264 | .dropdown-list {
265 | display: inline-block;
266 | position: relative;
267 | }
268 |
269 | .dropdown-list__items {
270 | position: absolute;
271 | top: 100%;
272 | left: 0;
273 | width: 200px;
274 | max-height: 0;
275 | margin-top: 8px;
276 | overflow: hidden;
277 | border-radius: 4px;
278 | opacity: 0;
279 | background: $purple-lighter;
280 | box-shadow: 0 3px 0 0 rgba(0, 0, 0, 0.15);
281 | transform: translateY(-15px);
282 | transition-property: opacity, transform;
283 | transition-duration: .3s;
284 |
285 | &.open {
286 | max-height: 1000px;
287 | opacity: 1;
288 | transform: translateY(0);
289 | z-index: 2;
290 | }
291 |
292 | &.left-side {
293 | left: auto;
294 | right: 0;
295 | }
296 | }
297 |
298 | .dropdown-list__item {
299 | &:first-child {
300 | padding-top: 7px;
301 | }
302 |
303 | &:last-child {
304 | padding-bottom: 7px;
305 | }
306 | }
307 |
308 | .dropdown-list__item__i {
309 | display: block;
310 | padding: 9px 20px;
311 | color: $white;
312 |
313 | &:hover, &:active {
314 | color: $white;
315 | background: $purple;
316 | }
317 | }
318 |
319 | /* Notifications */
320 |
321 | .notification__close {
322 | position: absolute;
323 | top: 2px;
324 | right: 7px;
325 | opacity: .2;
326 | font-size: 20px;
327 | line-height: 1;
328 | font-weight: bold;
329 | color: #000;
330 | text-shadow: 0 1px 0 #fff;
331 | cursor: pointer;
332 |
333 | &:hover {
334 | opacity: .5;
335 | }
336 | }
337 |
338 | .notification {
339 | position: relative;
340 | padding: 20px 35px 17px 15px;
341 | margin-bottom: 20px;
342 | border-radius: 4px;
343 | @extend .text-note;
344 | color: $white;
345 | background-color: $electric;
346 |
347 | &.success {
348 | background-color: $green;
349 | }
350 |
351 | &.warning {
352 | background-color: $yellow;
353 | }
354 |
355 | &.danger {
356 | color: $red;
357 | background-color: $system-red;
358 | }
359 |
360 | &.inline {
361 | margin: 0;
362 | display: inline-block;
363 | }
364 | }
365 |
366 | /* Tooltip */
367 |
368 | .tooltip {
369 | position: relative;
370 | }
371 |
372 | .tooltip__handler {
373 | cursor: default;
374 |
375 | &:hover {
376 | .tooltip__content {
377 | opacity: 1;
378 | pointer-events: auto;
379 | transform: translateY(0px);
380 | z-index: 10;
381 | }
382 | }
383 | }
384 |
385 | .tooltip__content {
386 | position: absolute;
387 | z-index: 2;
388 | margin-top: 5px;
389 | padding: 12px 16px 10px;
390 | opacity: 0;
391 | border-radius: 4px;
392 | @extend .text-regular;
393 | color: $primary-blue;
394 | background: $light-grey;
395 | box-shadow: 0 2px 0 0 rgba(0, 0, 0, 0.15);
396 | pointer-events: none;
397 | transform: translateY(10px);
398 | transition: all .25s ease-out;
399 |
400 | &.revert {
401 | right: 100%;
402 | margin-right: -18px;
403 |
404 | &:after {
405 | left: auto;
406 | right: 25px;
407 | }
408 | }
409 |
410 | &:after {
411 | content: '';
412 | position: absolute;
413 | top: -7px;
414 | left: 25px;
415 | height: 0;
416 | width: 0;
417 | border-left: solid transparent 6px;
418 | border-right: solid transparent 6px;
419 | border-bottom: solid $light-grey 7px;
420 | }
421 |
422 | & > div {
423 | display: table;
424 | white-space: nowrap;
425 | }
426 | }
427 |
428 | /* Title + Text block */
429 |
430 | .text-block {
431 | margin: 0 $margin 24px 0;
432 | }
433 |
434 | .text-block__title {
435 | margin-bottom: 10px;
436 | @extend .text-sub-title-light;
437 |
438 | &.emphasized {
439 | color: $primary-blue;
440 | }
441 | }
442 |
443 | .text-block__content {
444 | min-height: 30px;
445 |
446 | [type='text'],
447 | [type='password'],
448 | [type='email'],
449 | [type='tel'],
450 | textarea,
451 | select {
452 | position: relative;
453 | top: -6px;
454 | }
455 | }
456 |
457 | /* Labels */
458 |
459 | .label {
460 | display: inline-block;
461 | box-sizing: border-box;
462 | height: 20px;
463 | padding: 4px 10px 0;
464 | border-radius: 20px;
465 | font-size: $font-small;
466 | line-height: 1;
467 | font-weight: bold;
468 | white-space: nowrap;
469 | vertical-align: middle;
470 | text-transform: capitalize;
471 | text-align: center;
472 | color: #fff;
473 | background-color: $primary-grey;
474 |
475 | &.info {
476 | background-color: $electric;
477 | }
478 |
479 | &.success {
480 | background-color: $green;
481 | }
482 |
483 | &.danger,
484 | // deprecated
485 | &.alert {
486 | background-color: $red;
487 | }
488 |
489 | &.warning {
490 | background-color: $yellow;
491 | }
492 |
493 | &.error {
494 | color: $red;
495 | background-color: $system-red;
496 | }
497 |
498 | &.wide {
499 | min-width: 70px;
500 | }
501 |
502 | &.offset {
503 | position: relative;
504 | top: -2px;
505 | margin: 0 8px;
506 | text-transform: capitalize;
507 | }
508 |
509 | &.inlined {
510 | margin-right: 5px;
511 | }
512 | }
513 |
514 | /* Icons */
515 |
516 | .icon {
517 | display: inline-block;
518 |
519 | &.expand {
520 | width: 7px;
521 | height: 7px;
522 | border-left: 1px solid $primary-blue;
523 | border-top: 1px solid $primary-blue;
524 | transform: rotate(-135deg)
525 | }
526 | }
527 |
--------------------------------------------------------------------------------
/composer/src/test/resources/instrumentation-output-failed-test.txt:
--------------------------------------------------------------------------------
1 | adb shell am instrument -w -r -e numShards 20 -e shardIndex 1 com.example.test/android.support.test.runner.JunoAndroidRunner
2 | INSTRUMENTATION_STATUS: numtests=4
3 | INSTRUMENTATION_STATUS: stream=
4 | com.example.test.TestClass:
5 | INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
6 | INSTRUMENTATION_STATUS: test=test1
7 | INSTRUMENTATION_STATUS: class=com.example.test.TestClass
8 | INSTRUMENTATION_STATUS: current=1
9 | INSTRUMENTATION_STATUS_CODE: 1
10 | INSTRUMENTATION_STATUS: numtests=4
11 | INSTRUMENTATION_STATUS: stream=
12 | Error in test1(com.example.test.TestClass):
13 | java.net.UnknownHostException: Test Exception
14 | at com.example.test.TestClass.test1.1.invoke(TestClass.kt:245)
15 | at com.example.test.TestClass.test1.1.invoke(TestClass.kt:44)
16 | at com.example.test.TestClass.test1(TestClass.kt:238)
17 | at java.lang.reflect.Method.invoke(Native Method)
18 | at org.junit.runners.model.FrameworkMethod.1.runReflectiveCall(FrameworkMethod.java:50)
19 | at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
20 | at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
21 | at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
22 | at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
23 | at org.junit.rules.ExpectedException.ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
24 | at com.example.test.utils.LaunchAppRule.apply.1.evaluate(LaunchAppRule.kt:36)
25 | at com.example.test.utils.RetryRule.runTest(RetryRule.kt:43)
26 | at com.example.test.utils.RetryRule.access.runTest(RetryRule.kt:14)
27 | at com.example.test.utils.RetryRule.apply.1.evaluate(RetryRule.kt:29)
28 | at org.junit.rules.RunRules.evaluate(RunRules.java:20)
29 | at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
30 | at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
31 | at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
32 | at org.junit.runners.ParentRunner.3.run(ParentRunner.java:290)
33 | at org.junit.runners.ParentRunner.1.schedule(ParentRunner.java:71)
34 | at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
35 | at org.junit.runners.ParentRunner.access.000(ParentRunner.java:58)
36 | at org.junit.runners.ParentRunner.2.evaluate(ParentRunner.java:268)
37 | at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
38 | at org.junit.runners.Suite.runChild(Suite.java:128)
39 | at org.junit.runners.Suite.runChild(Suite.java:27)
40 | at org.junit.runners.ParentRunner.3.run(ParentRunner.java:290)
41 | at org.junit.runners.ParentRunner.1.schedule(ParentRunner.java:71)
42 | at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
43 | at org.junit.runners.ParentRunner.access.000(ParentRunner.java:58)
44 | at org.junit.runners.ParentRunner.2.evaluate(ParentRunner.java:268)
45 | at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
46 | at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
47 | at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
48 | at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
49 | at android.support.test.runner.JunoAndroidRunner.onStart(JunoAndroidRunner.kt:107)
50 | at android.app.Instrumentation.InstrumentationThread.run(Instrumentation.java:1932)
51 |
52 | INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
53 | INSTRUMENTATION_STATUS: test=test1
54 | INSTRUMENTATION_STATUS: class=com.example.test.TestClass
55 | INSTRUMENTATION_STATUS: stack=java.net.UnknownHostException: Test Exception
56 | at com.example.test.TestClass.test1.1.invoke(TestClass.kt:245)
57 | at com.example.test.TestClass.test1.1.invoke(TestClass.kt:44)
58 | at com.example.test.TestClass.test1(TestClass.kt:238)
59 | at java.lang.reflect.Method.invoke(Native Method)
60 | at org.junit.runners.model.FrameworkMethod.1.runReflectiveCall(FrameworkMethod.java:50)
61 | at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
62 | at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
63 | at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
64 | at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
65 | at org.junit.rules.ExpectedException.ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
66 | at com.example.test.utils.LaunchAppRule.apply.1.evaluate(LaunchAppRule.kt:36)
67 | at com.example.test.utils.RetryRule.runTest(RetryRule.kt:43)
68 | at com.example.test.utils.RetryRule.access.runTest(RetryRule.kt:14)
69 | at com.example.test.utils.RetryRule.apply.1.evaluate(RetryRule.kt:29)
70 | at org.junit.rules.RunRules.evaluate(RunRules.java:20)
71 | at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
72 | at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
73 | at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
74 | at org.junit.runners.ParentRunner.3.run(ParentRunner.java:290)
75 | at org.junit.runners.ParentRunner.1.schedule(ParentRunner.java:71)
76 | at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
77 | at org.junit.runners.ParentRunner.access.000(ParentRunner.java:58)
78 | at org.junit.runners.ParentRunner.2.evaluate(ParentRunner.java:268)
79 | at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
80 | at org.junit.runners.Suite.runChild(Suite.java:128)
81 | at org.junit.runners.Suite.runChild(Suite.java:27)
82 | at org.junit.runners.ParentRunner.3.run(ParentRunner.java:290)
83 | at org.junit.runners.ParentRunner.1.schedule(ParentRunner.java:71)
84 | at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
85 | at org.junit.runners.ParentRunner.access.000(ParentRunner.java:58)
86 | at org.junit.runners.ParentRunner.2.evaluate(ParentRunner.java:268)
87 | at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
88 | at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
89 | at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
90 | at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
91 | at android.support.test.runner.JunoAndroidRunner.onStart(JunoAndroidRunner.kt:107)
92 | at android.app.Instrumentation.InstrumentationThread.run(Instrumentation.java:1932)
93 |
94 | INSTRUMENTATION_STATUS: current=1
95 | INSTRUMENTATION_STATUS_CODE: -2
96 | INSTRUMENTATION_STATUS: numtests=4
97 | INSTRUMENTATION_STATUS: stream=
98 | INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
99 | INSTRUMENTATION_STATUS: test=test2
100 | INSTRUMENTATION_STATUS: class=com.example.test.TestClass
101 | INSTRUMENTATION_STATUS: current=2
102 | INSTRUMENTATION_STATUS_CODE: 1
103 | INSTRUMENTATION_STATUS: numtests=4
104 | INSTRUMENTATION_STATUS: stream=.
105 | INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
106 | INSTRUMENTATION_STATUS: test=test2
107 | INSTRUMENTATION_STATUS: class=com.example.test.TestClass
108 | INSTRUMENTATION_STATUS: current=2
109 | INSTRUMENTATION_STATUS_CODE: 0
110 | INSTRUMENTATION_STATUS: numtests=4
111 | INSTRUMENTATION_STATUS: stream=
112 | com.example.test.TestClass:
113 | INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
114 | INSTRUMENTATION_STATUS: test=test3
115 | INSTRUMENTATION_STATUS: class=com.example.test.TestClass
116 | INSTRUMENTATION_STATUS: current=3
117 | INSTRUMENTATION_STATUS_CODE: 1
118 | INSTRUMENTATION_STATUS: numtests=4
119 | INSTRUMENTATION_STATUS: stream=.
120 | INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
121 | INSTRUMENTATION_STATUS: test=test3
122 | INSTRUMENTATION_STATUS: class=com.example.test.TestClass
123 | INSTRUMENTATION_STATUS: current=3
124 | INSTRUMENTATION_STATUS_CODE: 0
125 | INSTRUMENTATION_STATUS: numtests=4
126 | INSTRUMENTATION_STATUS: stream=
127 | INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
128 | INSTRUMENTATION_STATUS: test=test4
129 | INSTRUMENTATION_STATUS: class=com.example.test.TestClass
130 | INSTRUMENTATION_STATUS: current=4
131 | INSTRUMENTATION_STATUS_CODE: 1
132 | INSTRUMENTATION_STATUS: numtests=4
133 | INSTRUMENTATION_STATUS: stream=.
134 | INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
135 | INSTRUMENTATION_STATUS: test=test4
136 | INSTRUMENTATION_STATUS: class=com.example.test.TestClass
137 | INSTRUMENTATION_STATUS: current=4
138 | INSTRUMENTATION_STATUS_CODE: 0
139 |
140 | Time: 96.641
141 | There was 1 failure:
142 | 1) test1(com.example.test.TestClass)
143 | java.net.UnknownHostException: Test Exception
144 | at com.example.test.TestClass.test1.1.invoke(TestClass.kt:245)
145 | at com.example.test.TestClass.test1.1.invoke(TestClass.kt:44)
146 | at com.example.test.screens.AddCreditCardScreen.Companion.invoke(AddCreditCardScreen.kt:23)
147 | at com.example.test.TestClass.test1(TestClass.kt:238)
148 | at java.lang.reflect.Method.invoke(Native Method)
149 | at org.junit.runners.model.FrameworkMethod.1.runReflectiveCall(FrameworkMethod.java:50)
150 | at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
151 | at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
152 | at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
153 | at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
154 | at org.junit.rules.ExpectedException.ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
155 | at com.example.test.utils.LaunchAppRule.apply.1.evaluate(LaunchAppRule.kt:36)
156 | at com.example.test.utils.RetryRule.runTest(RetryRule.kt:43)
157 | at com.example.test.utils.RetryRule.access.runTest(RetryRule.kt:14)
158 | at com.example.test.utils.RetryRule.apply.1.evaluate(RetryRule.kt:29)
159 | at org.junit.rules.RunRules.evaluate(RunRules.java:20)
160 | at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
161 | at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
162 | at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
163 | at org.junit.runners.ParentRunner.3.run(ParentRunner.java:290)
164 | at org.junit.runners.ParentRunner.1.schedule(ParentRunner.java:71)
165 | at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
166 | at org.junit.runners.ParentRunner.access.000(ParentRunner.java:58)
167 | at org.junit.runners.ParentRunner.2.evaluate(ParentRunner.java:268)
168 | at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
169 | at org.junit.runners.Suite.runChild(Suite.java:128)
170 | at org.junit.runners.Suite.runChild(Suite.java:27)
171 | at org.junit.runners.ParentRunner.3.run(ParentRunner.java:290)
172 | at org.junit.runners.ParentRunner.1.schedule(ParentRunner.java:71)
173 | at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
174 | at org.junit.runners.ParentRunner.access.000(ParentRunner.java:58)
175 | at org.junit.runners.ParentRunner.2.evaluate(ParentRunner.java:268)
176 | at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
177 | at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
178 | at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
179 | at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
180 | at android.support.test.runner.JunoAndroidRunner.onStart(JunoAndroidRunner.kt:107)
181 | at android.app.Instrumentation.InstrumentationThread.run(Instrumentation.java:1932)
182 |
183 | FAILURES!!!
184 | Tests run: 4, Failures: 1
185 |
186 |
187 | INSTRUMENTATION_CODE: -1
188 |
189 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Composer — Reactive Android Instrumentation Test Runner.
2 |
3 | Composer is a modern reactive replacement for [square/spoon][spoon] with following feature set:
4 |
5 | * Parallel test execution on multiple emulators/devices with [test sharding][test sharding] support.
6 | * Logcat output capturing per test and for whole test run as well.
7 | * Screenshots and files pulling for each test reactively (with support for [square/spoon][spoon] folder structure).
8 | * JUnit4 report generation.
9 |
10 | 
11 |
12 | ### Table of Contents
13 |
14 | - [Why we've decided to replace square/spoon](#why-weve-decided-to-replace-squarespoon)
15 | - [HTML Report](#html-report)
16 | - [Usage](#usage)
17 | - [Download](#download)
18 | - [3rd-party Composer Gradle Plugin](#3rd-party-composer-gradle-plugin)
19 | - [Swarmer](#swarmer)
20 | - [How to build](#how-to-build)
21 | - [License](#license)
22 |
23 | ### Why we've decided to replace [square/spoon][spoon]
24 |
25 | **Problem 1:** Our UI tests are stable, but we saw a lot of UI tests build failures. About ~50% of our CI builds were failing. All such failures of UI tests came from Spoon not being able to run tests on one or more emulators (device is red in the report and error message is `…work/emulator-5554/result.json (No such file or directory)`, basically it timed out on installing the apk on a device, increasing adb timeout did not help, all emulators responded to adb commands and mouse/keyboard interactions, we suppose problem is in in ddmlib used by Spoon.
26 |
27 | **Solution:** Composer does not use ddmlib and talks to emulators/devices by invoking `adb` binary.
28 |
29 | **Problem 2:** Pretty often when test run finished, Spoon freezed on moving screenshots from one of the emulators/devices. Again, we blame ddmlib used in Spoon for that.
30 |
31 | **Solution:** Composer invokes `adb` binary to pull files from emulators/devices, we haven't seen problems with that in more than 700 builds on CI.
32 |
33 | **Problem 3:** Spoon pulled screenshots/files *after* finish of the whole test run on a device which slows down builds: `test_run_time + pull_files_time`.
34 |
35 | **Solution:** Composer pulls screenshots/files *reactively* after each test which basically leads to: `~test_run_time`.
36 |
37 | **Problem 4:** If test sharding is enabled (which we do all the time), Spoon HTML report is very hard to look at, especially if you want to find some particular test(s) and it's not failed. You have to either hover mouse over each test to find out its name or go into html/xml source and find on which emulator/device test was sharded in order to click on correct device and then find test by CMD+F on the page.
38 |
39 | **Solution:** HTML report we've built designed with usability and performance in mind.
40 |
41 | **Problem 5:** Html report can be very slow to load if you have lots of screenshots (which we do) since it displays all the screenshots of tests that were run on a particular device on a single page — it can take up to minutes to finish while you effectively unable to scroll page since scroll is jumping up and down each time new screenshot loaded.
42 |
43 | **Solution:** HTML report that we've built does not display screenshots on index and suite pages, screenshots are displayed only on the test page → fast page load.
44 |
45 | >With Composer we were able to make UI tests required part of CI for Pull Requests.
46 | >It's fast, reliable and uses RxJava which means that it's relatively easy to add more features combining complex async transformations.
47 |
48 | ### HTML Report
49 |
50 | Our Frontend Team [helped us](https://github.com/gojuno/composer/issues/11) build HTML Report for the Composer.
51 |
52 | >It's fast, small and designed in collaboration with our QAs and Developers who actually use it on daily basis to make it easy to use.
53 |
54 | Here are few screenshots:
55 |
56 | [
](demo/screenshot1.png) [
](demo/screenshot2.png)[
](demo/screenshot3.png)
57 |
58 | ## Usage
59 |
60 | Composer shipped as jar, to run it you need JVM 1.8+: `java -jar composer-latest-version.jar options`.
61 |
62 | #### Supported options
63 |
64 | ##### Required
65 |
66 | * `--apk`
67 | * Either relative or absolute path to application apk that needs to be tested.
68 | * Example: `--apk myapp.apk`
69 | * `--test-apk`
70 | * Either relative or absolute path to apk with tests.
71 | * Example: `--test-apk myapp-androidTest.apk`
72 |
73 | ##### Optional
74 |
75 | * `--help, -help, help, -h`
76 | * Print help and exit.
77 | * `--test-runner`
78 | * Fully qualified name of test runner class you're using.
79 | * Default: automatically parsed from `--test-apk`'s `AndroidManifest`.
80 | * Example: `--test-runner com.example.TestRunner`
81 | * `--shard`
82 | * Either `true` or `false` to enable/disable [test sharding][test sharding] which statically shards tests between available devices/emulators.
83 | * Default: `true`.
84 | * Example: `--shard false`
85 | * `--output-directory`
86 | * Either relative or absolute path to directory for output: reports, files from devices and so on.
87 | * Default: `composer-output` in current working directory.
88 | * Example: `--output-directory artifacts/composer-output`
89 | * `--instrumentation-arguments`
90 | * Key-value pairs to pass to Instrumentation Runner.
91 | * Default: empty.
92 | * Example: `--instrumentation-arguments myKey1 myValue1 myKey2 myValue2`.
93 | * `--verbose-output`
94 | * Either `true` or `false` to enable/disable verbose output for Composer.
95 | * Default: `false`.
96 | * Example: `--verbose-output true`
97 | * `--keep-output-on-exit`
98 | * Either `true` or `false` to keep/clean temporary output files used by Composer on exit.
99 | * Default: `false`.
100 | * Composer uses files to pipe output of external commands like `adb`, keeping them might be useful for debugging issues.
101 | * Example: `--keep-output-on-exit true`
102 | * `--devices`
103 | * Connected devices/emulators that will be used to run tests against.
104 | * Default: empty, tests will run on all connected devices/emulators.
105 | * Specifying both `--devices` and `--device-pattern` will result in an error.
106 | * Example: `--devices emulator-5554 emulator-5556`
107 | * `--device-pattern`
108 | * Connected devices/emulators that will be used to run tests against.
109 | * Default: empty, tests will run on all connected devices/emulators.
110 | * Specifying both `--device-pattern` and `--devices` will result in an error.
111 | * Example: `--device-pattern "emulator.+"`
112 | * `--install-timeout`
113 | * APK installation timeout in seconds.
114 | * Default: `120` seconds (2 minutes).
115 | * Applicable to both test APK and APK under test.
116 | * Example: `--install-timeout 20`
117 | * `--fail-if-no-tests`
118 | * Either `true` or `false` to enable/disable error on empty test suite.
119 | * Default: `true`.
120 | * `False` may be applicable when you run tests conditionally(via annotation/package filters) and empty suite is a valid outcome.
121 | * Example: `--fail-if-no-tests false`
122 | * `--with-orchestrator`
123 | * Either `true` or `false` to enable/disable running tests via AndroidX Test Orchestrator.
124 | * Default: `false`.
125 | * When enabled - minimizes shared state and isolates test crashes.
126 | * Requires test orchestrator & test services APKs to be installed on device before executing.
127 | * More info: https://developer.android.com/training/testing/junit-runner#using-android-test-orchestrator
128 | * Example: `--with-orchestrator true`
129 | * `--extra-apks`
130 | * Apks to be installed for utilities. What you would typically declare in gradle as `androidTestUtil`
131 | * Default: empty, only apk and test apk would be installed.
132 | * Works great with Orchestrator to install orchestrator & test services APKs.
133 | * Example: `--extra-apks path/to/apk/first.apk path/to/apk/second.apk`
134 |
135 | ##### Example
136 |
137 | Simplest :
138 | ```console
139 | java -jar composer-latest-version.jar \
140 | --apk app/build/outputs/apk/example-debug.apk \
141 | --test-apk app/build/outputs/apk/example-debug-androidTest.apk
142 | ```
143 |
144 | With arguments :
145 | ```console
146 | java -jar composer-latest-version.jar \
147 | --apk app/build/outputs/apk/example-debug.apk \
148 | --test-apk app/build/outputs/apk/example-debug-androidTest.apk \
149 | --test-runner com.example.test.ExampleTestRunner \
150 | --output-directory artifacts/composer-output \
151 | --instrumentation-arguments key1 value1 key2 value2 \
152 | --verbose-output false \
153 | --keep-output-on-exit false \
154 | --with-orchestrator false
155 | ```
156 |
157 | ### Download
158 |
159 | Composer is [available on jcenter](https://jcenter.bintray.com/com/gojuno/composer).
160 |
161 | >You can download it in your CI scripts or store it in your version control system (not recommended).
162 |
163 | ```console
164 | COMPOSER_VERSION=some-version
165 | curl --fail --location https://jcenter.bintray.com/com/gojuno/composer/composer/${COMPOSER_VERSION}/composer-${COMPOSER_VERSION}.jar --output /tmp/composer.jar
166 | ```
167 |
168 | All the releases and changelogs can be found on [Releases Page](https://github.com/gojuno/composer/releases).
169 |
170 | ### 3rd-party Composer Gradle Plugin
171 |
172 | [@trevjonez](https://github.com/trevjonez) [built](https://github.com/gojuno/composer/issues/77) 🎉 [Gradle Plugin for Composer](https://github.com/trevjonez/composer-gradle-plugin) which allows you to configure and run Composer with Gradle.
173 |
174 | ### Swarmer
175 |
176 | Composer works great in combination with [Swarmer][swarmer] — another tool we've built at Juno.
177 |
178 | [Swarmer][swarmer] can create and start multiple emulators in parallel. In our [CI Pipeline][ci pipeline] we start emulators with Swarmer and then Composer runs tests on them.
179 |
180 | ### How to build
181 |
182 | #### All-in-one script (used in Travis build)
183 |
184 | Dependencies: `docker` and `bash`.
185 |
186 | ```console
187 | ci/build.sh
188 | ```
189 |
190 | #### Build Composer
191 |
192 | Environment variable `ANDROID_HOME` must be set.
193 |
194 | ```console
195 | ./gradlew build
196 | ```
197 |
198 | #### Build HTML report module
199 |
200 | Dependencies: `npm` and `nodejs`.
201 |
202 | ```console
203 | cd html-report
204 | npm install
205 | npm build
206 | ```
207 |
208 | ## License
209 |
210 | ```
211 | Copyright 2017 Juno, Inc.
212 |
213 | Licensed under the Apache License, Version 2.0 (the "License");
214 | you may not use this file except in compliance with the License.
215 | You may obtain a copy of the License at
216 |
217 | http://www.apache.org/licenses/LICENSE-2.0
218 |
219 | Unless required by applicable law or agreed to in writing, software
220 | distributed under the License is distributed on an "AS IS" BASIS,
221 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
222 | See the License for the specific language governing permissions and
223 | limitations under the License.
224 | ```
225 |
226 | [spoon]: https://github.com/square/spoon
227 | [test sharding]: https://developer.android.com/training/testing/junit-runner.html#sharding-tests
228 | [swarmer]: https://github.com/gojuno/swarmer
229 | [ci pipeline]: https://github.com/gojuno/engineering/tree/master/articles/ci_pipeline_and_custom_tools_of_android_projects
230 |
--------------------------------------------------------------------------------
/composer/src/main/kotlin/com/gojuno/composer/TestRun.kt:
--------------------------------------------------------------------------------
1 | package com.gojuno.composer
2 |
3 | import com.gojuno.commander.android.*
4 | import com.gojuno.commander.os.Notification
5 | import com.gojuno.commander.os.nanosToHumanReadableTime
6 | import com.gojuno.commander.os.process
7 | import rx.Observable
8 | import rx.Single
9 | import rx.schedulers.Schedulers
10 | import java.io.File
11 |
12 | data class AdbDeviceTestRun(
13 | val adbDevice: AdbDevice,
14 | val tests: List,
15 | val passedCount: Int,
16 | val ignoredCount: Int,
17 | val failedCount: Int,
18 | val durationNanos: Long,
19 | val timestampMillis: Long,
20 | val logcat: File,
21 | val instrumentationOutput: File
22 | )
23 |
24 | data class AdbDeviceTest(
25 | val adbDevice: AdbDevice,
26 | val className: String,
27 | val testName: String,
28 | val status: Status,
29 | val durationNanos: Long,
30 | val logcat: File,
31 | val files: List,
32 | val screenshots: List
33 | ) {
34 | sealed class Status {
35 | object Passed : Status()
36 | data class Ignored(val stacktrace: String) : Status()
37 | data class Failed(val stacktrace: String) : Status()
38 | }
39 | }
40 |
41 | fun AdbDevice.runTests(
42 | testPackageName: String,
43 | testRunnerClass: String,
44 | instrumentationArguments: String,
45 | outputDir: File,
46 | verboseOutput: Boolean,
47 | keepOutput: Boolean,
48 | useTestServices: Boolean
49 | ): Single {
50 |
51 | val adbDevice = this
52 | val logsDir = File(File(outputDir, "logs"), adbDevice.id)
53 | val instrumentationOutputFile = File(logsDir, "instrumentation.output")
54 | val commandPrefix = if (useTestServices) {
55 | "CLASSPATH=$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain "
56 | } else ""
57 |
58 | val runTests = process(
59 | commandAndArgs = listOf(
60 | adb,
61 | "-s", adbDevice.id,
62 | "shell", "${commandPrefix}am instrument -w -r $instrumentationArguments $testPackageName/$testRunnerClass"
63 | ),
64 | timeout = null,
65 | redirectOutputTo = instrumentationOutputFile,
66 | keepOutputOnExit = keepOutput
67 | ).share()
68 |
69 | @Suppress("destructure")
70 | val runningTests = runTests
71 | .ofType(Notification.Start::class.java)
72 | .flatMap { readInstrumentationOutput(it.output) }
73 | .asTests()
74 | .doOnNext { test ->
75 | val status = when (test.status) {
76 | is InstrumentationTest.Status.Passed -> "passed"
77 | is InstrumentationTest.Status.Ignored -> "ignored"
78 | is InstrumentationTest.Status.Failed -> "failed"
79 | }
80 |
81 | adbDevice.log(
82 | "Test ${test.index}/${test.total} $status in " +
83 | "${test.durationNanos.nanosToHumanReadableTime()}: " +
84 | "${test.className}.${test.testName}"
85 | )
86 | }
87 | .flatMap { test ->
88 | pullTestFiles(adbDevice, test, outputDir, verboseOutput)
89 | .toObservable()
90 | .subscribeOn(Schedulers.io())
91 | .map { pulledFiles -> test to pulledFiles }
92 | }
93 | .toList()
94 |
95 | val adbDeviceTestRun = Observable
96 | .zip(
97 | Observable.fromCallable { System.nanoTime() },
98 | runningTests,
99 | { time, tests -> time to tests }
100 | )
101 | .map { (startTimeNanos, testsWithPulledFiles) ->
102 | val tests = testsWithPulledFiles.map { it.first }
103 |
104 | AdbDeviceTestRun(
105 | adbDevice = adbDevice,
106 | tests = testsWithPulledFiles.map { (test, pulledFiles) ->
107 | AdbDeviceTest(
108 | adbDevice = adbDevice,
109 | className = test.className,
110 | testName = test.testName,
111 | status = when (test.status) {
112 | is InstrumentationTest.Status.Passed -> AdbDeviceTest.Status.Passed
113 | is InstrumentationTest.Status.Ignored -> AdbDeviceTest.Status.Ignored(test.status.stacktrace)
114 | is InstrumentationTest.Status.Failed -> AdbDeviceTest.Status.Failed(test.status.stacktrace)
115 | },
116 | durationNanos = test.durationNanos,
117 | logcat = logcatFileForTest(logsDir, test.className, test.testName),
118 | files = pulledFiles.files.sortedBy { it.name },
119 | screenshots = pulledFiles.screenshots.sortedBy { it.name }
120 | )
121 | },
122 | passedCount = tests.count { it.status is InstrumentationTest.Status.Passed },
123 | ignoredCount = tests.count { it.status is InstrumentationTest.Status.Ignored },
124 | failedCount = tests.count { it.status is InstrumentationTest.Status.Failed },
125 | durationNanos = System.nanoTime() - startTimeNanos,
126 | timestampMillis = System.currentTimeMillis(),
127 | logcat = logcatFileForDevice(logsDir),
128 | instrumentationOutput = instrumentationOutputFile
129 | )
130 | }
131 |
132 | val testRunFinish = runTests.ofType(Notification.Exit::class.java).cache()
133 |
134 | val saveLogcat = saveLogcat(adbDevice, logsDir)
135 | .map { Unit }
136 | // TODO: Stop when all expected tests were parsed from logcat and not when instrumentation finishes.
137 | // Logcat may be delivered with delay and that may result in missing logcat for last (n) tests (it's just a theory though).
138 | .takeUntil(testRunFinish)
139 | .startWith(Unit) // To allow zip finish normally even if no tests were run.
140 |
141 | return Observable
142 | .zip(adbDeviceTestRun, saveLogcat, testRunFinish) { suite, _, _ -> suite }
143 | .doOnSubscribe { adbDevice.log("Starting tests...") }
144 | .doOnNext { testRun ->
145 | adbDevice.log(
146 | "Test run finished, " +
147 | "${testRun.passedCount} passed, " +
148 | "${testRun.failedCount} failed, took " +
149 | "${testRun.durationNanos.nanosToHumanReadableTime()}."
150 | )
151 | }
152 | .doOnError { adbDevice.log("Error during tests run: $it") }
153 | .toSingle()
154 | }
155 |
156 | data class PulledFiles(
157 | val files: List,
158 | val screenshots: List
159 | )
160 |
161 | private fun pullTestFiles(adbDevice: AdbDevice, test: InstrumentationTest, outputDir: File, verboseOutput: Boolean): Single = Single
162 | // TODO: Add support for spoon files dir.
163 | .fromCallable {
164 | File(File(File(outputDir, "screenshots"), adbDevice.id), test.className).apply { mkdirs() }
165 | }
166 | .flatMap { screenshotsFolderOnHostMachine ->
167 | adbDevice
168 | .pullFolder(
169 | // TODO: Add support for internal storage and external storage strategies.
170 | folderOnDevice = "/storage/emulated/0/app_spoon-screenshots/${test.className}/${test.testName}",
171 | folderOnHostMachine = screenshotsFolderOnHostMachine,
172 | logErrors = verboseOutput
173 | )
174 | .map { File(screenshotsFolderOnHostMachine, test.testName) }
175 | }
176 | .map { screenshotsFolderOnHostMachine ->
177 | PulledFiles(
178 | files = emptyList(), // TODO: Pull test files.
179 | screenshots = screenshotsFolderOnHostMachine.let {
180 | when (it.exists()) {
181 | true -> it.listFiles().toList()
182 | else -> emptyList()
183 | }
184 | }
185 | )
186 | }
187 |
188 | internal fun String.parseTestClassAndName(): Pair? {
189 | val index = indexOf("TestRunner")
190 | if (index < 0) return null
191 |
192 | val tokens = substring(index, length).split(':')
193 | if (tokens.size != 3) return null
194 |
195 | val startedOrFinished = tokens[1].trimStart()
196 | if (startedOrFinished == "started" || startedOrFinished == "finished") {
197 | return tokens[2].substringAfter("(").removeSuffix(")") to tokens[2].substringBefore("(").trim()
198 | }
199 | return null
200 | }
201 |
202 | private fun saveLogcat(adbDevice: AdbDevice, logsDir: File): Observable> = Observable
203 | .just(logsDir to logcatFileForDevice(logsDir))
204 | .flatMap { (logsDir, fullLogcatFile) -> adbDevice.redirectLogcatToFile(fullLogcatFile).toObservable().map { logsDir to fullLogcatFile } }
205 | .flatMap { (logsDir, fullLogcatFile) ->
206 | data class result(val logcat: String = "", val startedTestClassAndName: Pair? = null, val finishedTestClassAndName: Pair? = null)
207 |
208 | tail(fullLogcatFile)
209 | .scan(result()) { previous, newline ->
210 | val logcat = when (previous.startedTestClassAndName != null && previous.finishedTestClassAndName != null) {
211 | true -> newline
212 | false -> "${previous.logcat}\n$newline"
213 | }
214 |
215 | // Implicitly expecting to see logs from `android.support.test.internal.runner.listener.LogRunListener`.
216 | // Was not able to find more reliable solution to capture logcat per test.
217 | val startedTest: Pair? = newline.parseTestClassAndName()
218 | val finishedTest: Pair? = newline.parseTestClassAndName()
219 |
220 | result(
221 | logcat = logcat,
222 | startedTestClassAndName = startedTest ?: previous.startedTestClassAndName,
223 | finishedTestClassAndName = finishedTest // Actual finished test should always overwrite previous.
224 | )
225 | }
226 | .filter { it.startedTestClassAndName != null && it.startedTestClassAndName == it.finishedTestClassAndName }
227 | .map { result ->
228 | logcatFileForTest(logsDir, className = result.startedTestClassAndName!!.first, testName = result.startedTestClassAndName.second)
229 | .apply { parentFile.mkdirs() }
230 | .writeText(result.logcat)
231 |
232 | result.startedTestClassAndName
233 | }
234 | }
235 |
236 | private fun logcatFileForDevice(logsDir: File) = File(logsDir, "full.logcat")
237 |
238 | private fun logcatFileForTest(logsDir: File, className: String, testName: String): File = File(File(logsDir, className), "$testName.logcat")
239 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2017 Juno Inc.
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/composer/src/main/kotlin/com/gojuno/composer/Main.kt:
--------------------------------------------------------------------------------
1 | package com.gojuno.composer
2 |
3 | import com.gojuno.commander.android.connectedAdbDevices
4 | import com.gojuno.commander.android.installApk
5 | import com.gojuno.commander.os.log
6 | import com.gojuno.commander.os.nanosToHumanReadableTime
7 | import com.gojuno.composer.html.writeHtmlReport
8 | import com.google.gson.Gson
9 | import rx.Observable
10 | import rx.schedulers.Schedulers
11 | import java.io.File
12 | import java.util.*
13 | import java.util.concurrent.TimeUnit
14 |
15 | sealed class Exit(val code: Int, val message: String?) {
16 | object Ok : Exit(code = 0, message = null)
17 | object NoDevicesAvailableForTests : Exit(code = 1, message = "Error: No devices available for tests.")
18 | class TestRunnerNotFound(message: String) : Exit(code = 1, message = message)
19 | class TestPackageNotFound(message: String) : Exit(code = 1, message = message)
20 | object ThereWereFailedTests : Exit(code = 1, message = "Error: There were failed tests.")
21 | object NoTests : Exit(code = 1, message = "Error: 0 tests were run.")
22 | }
23 |
24 | fun exit(exit: Exit) {
25 | if (exit.message != null) {
26 | log(exit.message)
27 | }
28 | System.exit(exit.code)
29 | }
30 |
31 | fun main(rawArgs: Array) {
32 | val startTime = System.nanoTime()
33 |
34 | val args = parseArgs(rawArgs)
35 |
36 | if (args.verboseOutput) {
37 | log("$args")
38 | }
39 |
40 | val testPackage: TestPackage.Valid = parseTestPackage(args.testApkPath).let {
41 | when (it) {
42 | is TestPackage.Valid -> it
43 | is TestPackage.ParseError -> {
44 | exit(Exit.TestPackageNotFound(message = it.error))
45 | return
46 | }
47 | }
48 | }
49 |
50 | val testRunner: TestRunner.Valid =
51 | if (!args.testRunner.isEmpty()) {
52 | TestRunner.Valid(args.testRunner)
53 | } else {
54 | parseTestRunner(args.testApkPath).let {
55 | when (it) {
56 | is TestRunner.Valid -> it
57 | is TestRunner.ParseError -> {
58 | exit(Exit.TestRunnerNotFound(message = it.error))
59 | return
60 | }
61 | }
62 | }
63 | }
64 |
65 | val suites = runAllTests(args, testPackage, testRunner)
66 |
67 | val duration = (System.nanoTime() - startTime)
68 |
69 | val totalPassed = suites.sumBy { it.passedCount }
70 | val totalFailed = suites.sumBy { it.failedCount }
71 | val totalIgnored = suites.sumBy { it.ignoredCount }
72 |
73 | log("Test run finished, total passed = $totalPassed, total failed = $totalFailed, total ignored = $totalIgnored, took ${duration.nanosToHumanReadableTime()}.")
74 |
75 | when {
76 | totalPassed > 0 && totalFailed == 0 -> exit(Exit.Ok)
77 | totalPassed == 0 && totalFailed == 0 -> if(args.failIfNoTests) exit(Exit.NoTests) else exit(Exit.Ok)
78 | else -> exit(Exit.ThereWereFailedTests)
79 | }
80 |
81 | log("Test run finished took ${duration.nanosToHumanReadableTime()}.")
82 | exit(Exit.Ok)
83 | }
84 |
85 | private fun runAllTests(args: Args, testPackage: TestPackage.Valid, testRunner: TestRunner.Valid): List {
86 | val gson = Gson()
87 |
88 | return connectedAdbDevices()
89 | .map { devices ->
90 | when (args.devicePattern.isEmpty()) {
91 | true -> devices
92 | false -> Regex(args.devicePattern).let { regex -> devices.filter { regex.matches(it.id) } }
93 | }
94 | }
95 | .map {
96 | when (args.devices.isEmpty()) {
97 | true -> it
98 | false -> it.filter { args.devices.contains(it.id) }
99 | }
100 | }
101 | .map {
102 | it.filter { it.online }.apply {
103 | if (isEmpty()) {
104 | exit(Exit.NoDevicesAvailableForTests)
105 | }
106 | }
107 | }
108 | .doOnNext { log("${it.size} connected adb device(s): $it") }
109 | .flatMap { connectedAdbDevices ->
110 | val runTestsOnDevices: List> = connectedAdbDevices.mapIndexed { index, device ->
111 | val installTimeout = Pair(args.installTimeoutSeconds, TimeUnit.SECONDS)
112 | val installAppApk = device.installApk(pathToApk = args.appApkPath, timeout = installTimeout)
113 | val installTestApk = device.installApk(pathToApk = args.testApkPath, timeout = installTimeout)
114 | val installApks = mutableListOf(installAppApk, installTestApk)
115 | installApks.addAll(args.extraApks.map {
116 | device.installApk(pathToApk = it, timeout = installTimeout)
117 | })
118 |
119 | Observable
120 | .concat(installApks)
121 | // Work with each device in parallel, but install apks sequentially on a device.
122 | .subscribeOn(Schedulers.io())
123 | .toList()
124 | .flatMap {
125 | val targetInstrumentation: List>
126 | val testPackageName: String
127 | val testRunnerClass: String
128 |
129 | if (args.runWithOrchestrator) {
130 | targetInstrumentation = listOf("targetInstrumentation" to "${testPackage.value}/${testRunner.value}")
131 | testPackageName = "androidx.test.orchestrator"
132 | testRunnerClass = "androidx.test.orchestrator.AndroidTestOrchestrator"
133 | } else {
134 | targetInstrumentation = emptyList()
135 | testPackageName = testPackage.value
136 | testRunnerClass = testRunner.value
137 | }
138 |
139 | val instrumentationArguments =
140 | buildShardArguments(
141 | shardingOn = args.shard,
142 | shardIndex = index,
143 | devices = connectedAdbDevices.size
144 | ) + args.instrumentationArguments.pairArguments() + targetInstrumentation
145 |
146 | device
147 | .runTests(
148 | testPackageName = testPackageName,
149 | testRunnerClass = testRunnerClass,
150 | instrumentationArguments = instrumentationArguments.formatInstrumentationArguments(),
151 | outputDir = File(args.outputDirectory),
152 | verboseOutput = args.verboseOutput,
153 | keepOutput = args.keepOutputOnExit,
154 | useTestServices = args.runWithOrchestrator
155 | )
156 | .flatMap { adbDeviceTestRun ->
157 | writeJunit4Report(
158 | suite = adbDeviceTestRun.toSuite(testPackage.value),
159 | outputFile = File(File(args.outputDirectory, "junit4-reports"), "${device.id}.xml")
160 | ).toSingleDefault(adbDeviceTestRun)
161 | }
162 | .subscribeOn(Schedulers.io())
163 | .toObservable()
164 | }
165 | }
166 | Observable.zip(runTestsOnDevices, { results -> results.map { it as AdbDeviceTestRun } })
167 | }
168 | .map { adbDeviceTestRuns ->
169 | when (args.shard) {
170 | true -> {// In "shard=true" mode test runs from all devices arecombined into one suite of tests.
171 | listOf(Suite(
172 | testPackage = testPackage.value,
173 | devices = adbDeviceTestRuns.fold(emptyList()) { devices, adbDeviceTestRun ->
174 | devices + Device(
175 | id = adbDeviceTestRun.adbDevice.id,
176 | model = adbDeviceTestRun.adbDevice.model,logcat = adbDeviceTestRun.logcat,
177 | instrumentationOutput = adbDeviceTestRun.instrumentationOutput
178 | )
179 | },
180 | tests = adbDeviceTestRuns.map { it.tests }.fold(emptyList()) { result, tests ->
181 | result + tests
182 | },
183 | passedCount = adbDeviceTestRuns.sumBy { it.passedCount },
184 | ignoredCount = adbDeviceTestRuns.sumBy { it.ignoredCount },
185 | failedCount = adbDeviceTestRuns.sumBy { it.failedCount },
186 | durationNanos = adbDeviceTestRuns.map { it.durationNanos }.max() ?: -1,
187 | timestampMillis = adbDeviceTestRuns.map { it.timestampMillis }.min() ?: -1
188 | ))}
189 |
190 | false -> {
191 | // In "shard=false" mode test run from each device is represented as own suite of tests.
192 | adbDeviceTestRuns.map {
193 | it.toSuite(testPackage.value)
194 | }
195 | }
196 | }
197 | }
198 | .flatMap { suites ->
199 | log("Generating HTML report...")
200 | val htmlReportStartTime = System.nanoTime()
201 | writeHtmlReport(gson, suites, File(args.outputDirectory, "html-report"), Date())
202 | .doOnCompleted { log("HTML report generated, took ${(System.nanoTime() - htmlReportStartTime).nanosToHumanReadableTime()}.") }
203 | .andThen(Observable.just(suites))
204 | }
205 | .toBlocking()
206 | .first()
207 | }
208 |
209 | private fun List.pairArguments(): List> =
210 | foldIndexed(mutableListOf()) { index, accumulator, value ->
211 | accumulator.apply {
212 | if (index % 2 == 0) {
213 | add(value to "")
214 | } else {
215 | set(lastIndex, last().first to value)
216 | }
217 | }
218 | }
219 |
220 | private fun buildSingleTestArguments(testMethod : String) : List> =
221 | listOf("class" to testMethod)
222 |
223 | private fun buildShardArguments(shardingOn: Boolean, shardIndex: Int, devices: Int): List> = when {
224 | shardingOn && devices > 1 -> listOf(
225 | "numShards" to "$devices",
226 | "shardIndex" to "$shardIndex"
227 | )
228 |
229 | else -> emptyList()
230 | }
231 |
232 | private fun List>.formatInstrumentationArguments(): String = when (isEmpty()) {
233 | true -> ""
234 | false -> " " + joinToString(separator = " ") { "-e ${it.first} ${it.second}" }
235 | }
236 |
237 | data class Suite(
238 | val testPackage: String,
239 | val devices: List,
240 | val tests: List, // TODO: switch to separate Test class.
241 | val passedCount: Int,
242 | val ignoredCount: Int,
243 | val failedCount: Int,
244 | val durationNanos: Long,
245 | val timestampMillis: Long
246 | )
247 |
248 | data class Device(
249 | val id: String,
250 | val model:String,
251 | val logcat: File,
252 | val instrumentationOutput: File
253 | )
254 |
255 | fun AdbDeviceTestRun.toSuite(testPackage: String): Suite = Suite(
256 | testPackage = testPackage,
257 | devices = listOf(Device(
258 | id = adbDevice.id,
259 | model = adbDevice.model,
260 | logcat = logcat,
261 | instrumentationOutput = instrumentationOutput
262 | )),
263 | tests = tests,
264 | passedCount = passedCount,
265 | ignoredCount = ignoredCount,
266 | failedCount = failedCount,
267 | durationNanos = durationNanos,
268 | timestampMillis = timestampMillis
269 | )
270 |
--------------------------------------------------------------------------------