This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Add coverage report #148
Open
tokou
wants to merge
3
commits into
gojuno:master
Choose a base branch
from
tokou:coverage_reports
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add coverage report #148
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.gojuno.composer | ||
|
||
import com.gojuno.commander.android.adb | ||
import com.gojuno.commander.android.connectedAdbDevices | ||
import com.gojuno.commander.android.installApk | ||
import com.gojuno.commander.os.log | ||
import com.gojuno.commander.os.nanosToHumanReadableTime | ||
import com.gojuno.commander.os.process | ||
import com.gojuno.composer.html.writeHtmlReport | ||
import com.google.gson.Gson | ||
import rx.Observable | ||
|
@@ -111,15 +113,25 @@ private fun runAllTests(args: Args, testPackage: TestPackage.Valid, testRunner: | |
val installTimeout = Pair(args.installTimeoutSeconds, TimeUnit.SECONDS) | ||
val installAppApk = device.installApk(pathToApk = args.appApkPath, timeout = installTimeout) | ||
val installTestApk = device.installApk(pathToApk = args.testApkPath, timeout = installTimeout) | ||
val coverageDir = "/storage/emulated/0/app_coverage/${testPackage.value}" | ||
val makeCoverageDir = if (args.coverage) { | ||
process(commandAndArgs = listOf(adb, "-s", device.id, "shell", "mkdir", "-p", coverageDir)) | ||
.map { Unit } | ||
} else { | ||
Observable.just(Unit) | ||
} | ||
|
||
Observable | ||
.concat(installAppApk, installTestApk) | ||
.concat(installAppApk, installTestApk, makeCoverageDir) | ||
// Work with each device in parallel, but install apks sequentially on a device. | ||
.subscribeOn(Schedulers.io()) | ||
.toList() | ||
.flatMap { | ||
val instrumentationArguments = | ||
buildShardArguments( | ||
buildCoverageArguments( | ||
coverage = args.coverage, | ||
coverageDir = coverageDir | ||
) + buildShardArguments( | ||
shardingOn = args.shard, | ||
shardIndex = index, | ||
devices = connectedAdbDevices.size | ||
|
@@ -132,7 +144,8 @@ private fun runAllTests(args: Args, testPackage: TestPackage.Valid, testRunner: | |
instrumentationArguments = instrumentationArguments.formatInstrumentationArguments(), | ||
outputDir = File(args.outputDirectory), | ||
verboseOutput = args.verboseOutput, | ||
keepOutput = args.keepOutputOnExit | ||
keepOutput = args.keepOutputOnExit, | ||
coverage = args.coverage | ||
) | ||
.flatMap { adbDeviceTestRun -> | ||
writeJunit4Report( | ||
|
@@ -210,6 +223,12 @@ private fun buildShardArguments(shardingOn: Boolean, shardIndex: Int, devices: I | |
else -> emptyList() | ||
} | ||
|
||
private fun buildCoverageArguments(coverage: Boolean, coverageDir: String): List<Pair<String, String>> = | ||
if (coverage) listOf( | ||
"coverage" to "true", | ||
"coverageFile" to "$coverageDir/coverage.ec" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be |
||
) else emptyList() | ||
|
||
private fun List<Pair<String, String>>.formatInstrumentationArguments(): String = when (isEmpty()) { | ||
true -> "" | ||
false -> " " + joinToString(separator = " ") { "-e ${it.first} ${it.second}" } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we use
EXTERNAL_STORAGE
environment variable instead of hardcoding external storage directory?