/** Write the junit report xml file. */ private void writeJunitReportToFile() { try { final String directory = String.valueOf(targetDirectory) + "/surefire-reports"; FileUtils.forceMkdir(new File(directory)); final StringBuilder b = new StringBuilder(directory) .append("/TEST-") .append(DeviceHelper.getDescriptiveName(device)); if (StringUtils.isNotBlank(reportSuffix)) { // Safety first b.append(reportSuffix.replace("/", "").replace("\\", "")); } final File reportFile = new File(b.append(".xml").toString()); final JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class); final Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(report, reportFile); getLog().info(deviceLogLinePrefix + "Report file written to " + reportFile.getAbsolutePath()); } catch (IOException e) { threwException = true; exceptionMessages.append("Failed to write test report file"); exceptionMessages.append(e.getMessage()); } catch (JAXBException e) { threwException = true; exceptionMessages.append("Failed to create jaxb context"); exceptionMessages.append(e.getMessage()); } }
/** * Create a new test run listener. * * @param device the device on which test is executed. */ public AndroidTestRunListener( IDevice device, Log log, Boolean createReport, Boolean takeScreenshotOnFailure, String screenshotsPathOnDevice, String reportSuffix, File targetDirectory) { this.device = device; this.deviceLogLinePrefix = DeviceHelper.getDeviceLogLinePrefix(device); this.log = log; this.createReport = createReport; this.takeScreenshotOnFailure = takeScreenshotOnFailure; this.screenshotsPathOnDevice = screenshotsPathOnDevice; this.reportSuffix = reportSuffix; this.targetDirectory = targetDirectory; }