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

Add JUnit XML report output for each device. #106

merged 2 commits into from
Jun 5, 2013

Conversation

JakeWharton
Copy link
Collaborator

Closes #100.

@RichardGuion
Copy link

There are 2 problems with the code. One: it creates a directory with the format <serial_number>.xml instead of a file. Two: it doesn't create an xml file with results because XmlTestRunListener getResultFile was confused over the File parameter vs the File member object.

I tried pushing a branch to you and it failed, so here is the code to fix it. After I made these changes, the xml files were generated in the junit_report directory.

SpoonDeviceRunner

public final class SpoonDeviceRunner {
private static final String FILE_EXECUTION = "execution.json";
private static final String FILE_RESULT = "result.json";
static final String TEMP_DIR = "work";
static final String JUNIT_DIR = "junit-reports";

private final File sdk;
private final File apk;
private final File testApk;
private final String serial;
private final boolean debug;
private final File output;
private final String className;
private final String methodName;
private final File work;
private final File junitReport;
private final File junitReportDir;
private final String classpath;
private final SpoonInstrumentationInfo instrumentationInfo;

/**

  • Create a test runner for a single device.
    *
  • @param sdk Path to the local Android SDK directory.
  • @param apk Path to application APK.
  • @param testApk Path to test application APK.
  • @param output Path to output directory.
  • @param serial Device to run the test on.
  • @param debug Whether or not debug logging is enabled.
  • @param classpath Custom JVM classpath or {@code null}.
  • @param instrumentationInfo Test apk manifest information.
  • @param className Test class name to run or {@code null} to run all tests.
  • @param methodName Test method name to run or {@code null} to run all tests. Must also pass
  •    {@code className}.
    
    */
    SpoonDeviceRunner(File sdk, File apk, File testApk, File output, String serial, boolean debug,
    String classpath, SpoonInstrumentationInfo instrumentationInfo, String className,
    String methodName) {
    this.sdk = sdk;
    this.apk = apk;
    this.testApk = testApk;
    this.serial = serial;
    this.debug = debug;
    this.output = output;
    this.className = className;
    this.methodName = methodName;
    this.work = FileUtils.getFile(output, TEMP_DIR, serial);
    this.junitReportDir = FileUtils.getFile(output, JUNIT_DIR);
    this.junitReport = FileUtils.getFile(output, JUNIT_DIR, serial + ".xml");
    this.classpath = classpath;
    this.instrumentationInfo = instrumentationInfo;
    }

....

/** Execute instrumentation on the target device and return a result summary. */
public DeviceResult run(AndroidDebugBridge adb) {
....
// Run all the tests! o/
try {
logDebug(debug, "About to actually run tests for [%s]", serial);

  // create the directory for junit report result
  junitReportDir.mkdirs();

  RemoteAndroidTestRunner runner = new RemoteAndroidTestRunner(testPackage, testRunner, device);

XmlTestRunListener:

class XmlTestRunListener extends com.android.ddmlib.testrunner.XmlTestRunListener {
private final File xmlResultFile;

XmlTestRunListener(File file) {
this.xmlResultFile = file;
}

@OverRide protected File getResultFile(File file) throws IOException {
return xmlResultFile;
}
}

@JakeWharton
Copy link
Collaborator Author

I already fixed that and tested it with 6 devices. It generates a folder with 6 XML files using the serial as the filename.

@RichardGuion
Copy link

Great! Glad to see all this Spoon activity. :-)

holmes added a commit that referenced this pull request Jun 5, 2013
Add JUnit XML report output for each device.
@holmes holmes merged commit 0900b73 into master Jun 5, 2013
@JakeWharton JakeWharton deleted the jw/updates branch November 25, 2013 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XML output for Jenkins intergration
3 participants