Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running tests from a shard in a single instrumentation call #514

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion spoon-runner/src/main/java/com/squareup/spoon/CliArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ internal class CliArgs(parser: ArgParser) {
val coverage by parser.flagging("Enable code coverage")

val singleInstrumentationCall by parser.flagging("--single-instrumentation-call",
help = "Run all tests in a single instrumentation call")
help = "Run tests in a single instrumentation call. If sharding is enabled each shard " +
"will be in a single instrumentation call otherwise all tests will be run.")

private fun validateInstrumentationArgs() {
val isTestRunPackageLimited = instrumentationArgs?.contains("package") ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,20 @@ public DeviceResult run(AndroidDebugBridge adb) {
result.startTests();
multiRunListener.multiRunStarted(recorder.runName(), recorder.testCount());
if (singleInstrumentationCall) {
logDebug(debug, "Running all tests in a single instrumentation call [%s]", serial);
logDebug(debug, "Running tests in a single instrumentation call [%s]", serial);
try {
runAllTestOnDevice(testPackage, testRunner, device, listeners);
if (numShards != 0) {
runTestShardOnDevice(testPackage, testRunner, device, listeners);
} else {
runAllTestsOnDevice(testPackage, testRunner, device, listeners);
}
} catch (Exception e) {
result.addException(e);
}
} else {
for (TestIdentifier test : activeTests) {
try {
runTestOnDevice(testPackage, testRunner, device, listeners, test);
runSingleTestOnDevice(testPackage, testRunner, device, listeners, test);
} catch (Exception e) {
result.addException(e);
}
Expand Down Expand Up @@ -316,29 +320,34 @@ private LogRecordingTestRunListener queryTestSet(final String testPackage,
return recorder;
}

private void runAllTestOnDevice(final String testPackage, final String testRunner,
private void runAllTestsOnDevice(final String testPackage, final String testRunner,
final IDevice device, final List<ITestRunListener> listeners) throws Exception {

logDebug(debug, "Running tests [%s]", serial);

RemoteAndroidTestRunner runner = createConfiguredRunner(testPackage, testRunner, device);
runner.run(listeners);
}

private void runTestShardOnDevice(final String testPackage, final String testRunner,
final IDevice device, final List<ITestRunListener> listeners) throws Exception {

runTestOnDevice(testPackage, testRunner, device, listeners, null);
logDebug(debug, "Running tests for shardIndex [%d] out of numShards [%s] on [%s]",
shardIndex, numShards, serial);
RemoteAndroidTestRunner runner = createConfiguredRunner(testPackage, testRunner, device);
addShardingInstrumentationArgs(runner);
runner.run(listeners);
}

private void runTestOnDevice(final String testPackage, final String testRunner,
private void runSingleTestOnDevice(final String testPackage, final String testRunner,
final IDevice device, final List<ITestRunListener> listeners,
@Nullable final TestIdentifier test) throws Exception {

if (test != null) {
logDebug(debug, "Running %s [%s]", test, serial);
} else {
logDebug(debug, "Running tests [%s]", serial);
}
logDebug(debug, "Running %s on [%s]", test, serial);

RemoteAndroidTestRunner runner = createConfiguredRunner(testPackage, testRunner, device);
runner.removeInstrumentationArg("package");
if (codeCoverage) {
addCodeCoverageInstrumentationArgs(runner, device);
}
if (test != null) {
runner.setMethodName(test.getClassName(), test.getTestName());
}
runner.setMethodName(test.getClassName(), test.getTestName());
runner.run(listeners);
}

Expand All @@ -356,6 +365,9 @@ private RemoteAndroidTestRunner createConfiguredRunner(String testPackage, Strin
}
runner.addInstrumentationArg(entry.getKey(), entry.getValue());
}
if (codeCoverage) {
addCodeCoverageInstrumentationArgs(runner, device);
}
return runner;
}

Expand Down