Skip to content
This repository was archived by the owner on Dec 7, 2019. It is now read-only.

Added parsing of test runner and test package from apk-s.#119

Merged
yunikkk merged 1 commit intogojuno:masterfrom
yunikkk:parse-info-from-apk
Feb 24, 2018
Merged

Added parsing of test runner and test package from apk-s.#119
yunikkk merged 1 commit intogojuno:masterfrom
yunikkk:parse-info-from-apk

Conversation

@yunikkk
Copy link
Copy Markdown
Contributor

@yunikkk yunikkk commented Jan 13, 2018

No description provided.

)
var testPackage: String = "",

@Parameter(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artem-zinnatullin not sure if we still need that argument. I can imagine choosing from multiple runners in one test apk, though use cases are not clear. WDYT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's now optional I'd leave it, but we need to update README and remove it from examples

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sure

Copy link
Copy Markdown
Collaborator

@artem-zinnatullin artem-zinnatullin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess weed is now legal in Belarus or I don't understand something lol

)
var testPackage: String = "",

@Parameter(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's now optional I'd leave it, but we need to update README and remove it from examples

names = arrayOf("--verbose-output"),
required = false,
arity = 1,
description = "Either `true` or `false` to enable/disable verbose output for Composer. `false` by default.",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked "Either x or y" part, otherwise it's not obvious that you can pass booleans

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will return it.

required = false,
description = "APK installation timeout in seconds. If not passed defaults to 120 seconds (2 minutes). Applicable to both test APK and APK under test.",
order = 11
order = 10
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't remember why order is important here and certainly don't like that we need to maintain it manually..

Copy link
Copy Markdown
Contributor Author

@yunikkk yunikkk Jan 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Args are sorted alphabetically in -help without order specified =(

log("$args")
}

val testPackage = getTestPackageFromTestApk(args.testApkPath)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to parseTestPackage(testApkFile = File(args.testApkPath))?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

.toList()
.flatMap {
val testRunner = if (args.testRunner.isEmpty()) {
device.getTestRunnerForInstalledTestApk(testPackage)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

querying every device to get info that we can parse from apk looks very strange to me O_o

val totalPassed = suites.sumBy { it.passedCount }
val totalFailed = suites.sumBy { it.failedCount }
val totalIgnored = suites.sumBy { it.ignoredCount }
fun AdbDevice.getTestRunnerFromTestApk(): Single<String> =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wuuut, why do we need to query device for that?

Can't we parse it from apk? This info should be in the manifest

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, mostly, it seemed to be the simpler way.
However, I've just found that aapt is capable of parsing the whole manifest as well, so we won't need to do it manually.
Will change it then.

PS. Actually getTestRunnerFromTestApk is duplicating getTestRunnerForInstalledTestApk defined below, its just and old one.

.toSingle()

log("Test run finished, total passed = $totalPassed, total failed = $totalFailed, total ignored = $totalIgnored, took ${duration.nanosToHumanReadableTime()}.")
private fun getTestPackageFromTestApk(testApkPath: String): String =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a test for that maaaan

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just drop dummy apk into test/resources or even add a dummy android module to the project and use its build results as test input

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OKAY

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used dummy apk

else -> exit(Exit.ThereWereFailedTests)
}
}
private fun AdbDevice.getTestRunnerForInstalledTestApk(testPackage: String): String =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here, why not parse it from apk?

@artem-zinnatullin
Copy link
Copy Markdown
Collaborator

narkoman chto li

@artem-zinnatullin artem-zinnatullin self-assigned this Jan 18, 2018
@yunikkk
Copy link
Copy Markdown
Contributor Author

yunikkk commented Jan 19, 2018

niet.

@yunikkk yunikkk force-pushed the parse-info-from-apk branch 2 times, most recently from 6589816 to c224516 Compare January 22, 2018 23:35
output
.readText()
.split(System.lineSeparator())
// output format `package: name='$testPackage' versionCode='' versionName='' platformBuildVersionName='xxx'`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice comment, lois

.first { it.startsWith("name=") }
.split("'")[1]
}
.onErrorReturn { "" }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets propagate error up or make a sealed class for result? Otherwise we're kinda using one possible state of string as error indicator

import com.gojuno.commander.os.Notification
import com.gojuno.commander.os.process

fun parseTestPackage(testApkPath: String): String =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expose it as Single<String>, up2u


val testApkPath by memoized { fileFromJarResources<InstrumentationSpec>("instrumentation-test.apk").absolutePath }

it("test runner is parsed correctly") {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it("parses test runner correctly"), ingilish, do u speak it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runglish lol

assertThat(getTestRunner(testApkPath)).isEqualTo("android.support.test.runner.AndroidJUnitRunner")
}

it("test package is parsed correctly") {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@yunikkk yunikkk force-pushed the parse-info-from-apk branch from c224516 to 27f6c65 Compare February 1, 2018 21:39
@yunikkk
Copy link
Copy Markdown
Contributor Author

yunikkk commented Feb 2, 2018

@artem-zinnatullin PTAL

?.split(" ")
?.firstOrNull { it.startsWith("name=") }
?.split("'")
?.getOrNull(1)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

j.?e.?e.?z?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too long =)

@yunikkk yunikkk force-pushed the parse-info-from-apk branch 2 times, most recently from a8489a8 to c8ece72 Compare February 8, 2018 21:19
@yunikkk yunikkk force-pushed the parse-info-from-apk branch from c8ece72 to d769712 Compare February 24, 2018 13:14
@yunikkk yunikkk merged commit f78b3b0 into gojuno:master Feb 24, 2018
@yunikkk yunikkk deleted the parse-info-from-apk branch February 25, 2018 12:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants