Skip to content

Add JUnit XML report output for each device. #106

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

Merged
merged 2 commits into from
Jun 5, 2013
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
public final class SpoonDeviceRunner {
private static final String FILE_EXECUTION = "execution.json";
private static final String FILE_RESULT = "result.json";
private static final int ADB_TIMEOUT = 60 * 1000;
static final String TEMP_DIR = "work";
static final String JUNIT_DIR = "junit-reports";

private final File sdk;
private final File apk;
Expand All @@ -48,6 +50,7 @@ public final class SpoonDeviceRunner {
private final String className;
private final String methodName;
private final File work;
private final File junitReport;
private final String classpath;
private final SpoonInstrumentationInfo instrumentationInfo;

Expand Down Expand Up @@ -78,6 +81,7 @@ public final class SpoonDeviceRunner {
this.className = className;
this.methodName = methodName;
this.work = FileUtils.getFile(output, TEMP_DIR, serial);
this.junitReport = FileUtils.getFile(output, JUNIT_DIR, serial + ".xml");
this.classpath = classpath;
this.instrumentationInfo = instrumentationInfo;
}
Expand Down Expand Up @@ -163,21 +167,28 @@ public DeviceResult run(AndroidDebugBridge adb) {
return result.markInstallAsFailed(e.getMessage()).build();
}

// Create the output directory, if it does not already exist.
work.mkdirs();

// Initiate device logging.
SpoonDeviceLogger deviceLogger = new SpoonDeviceLogger(device);

// Run all the tests! o/
try {
logDebug(debug, "About to actually run tests for [%s]", serial);
RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner(testPackage, testRunner, device);
runner.setMaxtimeToOutputResponse(ADB_TIMEOUT);
if (!Strings.isNullOrEmpty(className)) {
if (Strings.isNullOrEmpty(methodName)) {
runner.setClassName(className);
} else {
runner.setMethodName(className, methodName);
}
}
runner.run(new SpoonTestRunListener(result, debug));
runner.run(
new SpoonTestRunListener(result, debug),
new XmlTestRunListener(junitReport)
);
} catch (Exception e) {
result.addException(e);
}
Expand All @@ -193,8 +204,6 @@ public DeviceResult run(AndroidDebugBridge adb) {

try {
logDebug(debug, "About to grab screenshots and prepare output for [%s]", serial);
// Create the output directory, if it does not already exist.
work.mkdirs();

// Sync device screenshots, if any, to the local filesystem.
String dirName = "app_" + SPOON_SCREENSHOTS;
Expand Down Expand Up @@ -252,15 +261,7 @@ public DeviceResult run(AndroidDebugBridge adb) {
result.getMethodResultBuilder(deviceTest).setAnimatedGif(animatedGif);
}
}
try {
FileUtils.deleteDirectory(screenshotDir);
} catch (IOException ignored) {
// DDMS r16 bug on Windows. Le sigh.
logInfo(
"Warning: IOException when trying to delete %s. If you're not on Windows, panic.",
screenshotDir);
FileUtils.forceDeleteOnExit(screenshotDir);
}
FileUtils.deleteDirectory(screenshotDir);
}
} catch (Exception e) {
result.addException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.squareup.spoon;

import java.io.File;
import java.io.IOException;

/**
* An {@link com.android.ddmlib.testrunner.XmlTestRunListener XmlTestRunListener} that points
* directly to an output file.
*/
class XmlTestRunListener extends com.android.ddmlib.testrunner.XmlTestRunListener {
private final File file;

XmlTestRunListener(File file) {
if (file == null) {
throw new IllegalArgumentException("File may not be null.");
}
this.file = file;
}

@Override protected File getResultFile(File reportDir) throws IOException {
file.getParentFile().mkdirs();
return file;
}
}