protected void collect(Project project, SensorContext context, File reportsDir) { LOGGER.info("parsing {}", reportsDir); surefireJavaParser.collect(project, context, reportsDir); }
private File[] getReports(File dir) { if (dir == null) { return new File[0]; } else if (!dir.isDirectory()) { LOGGER.warn("Reports path not found: " + dir.getAbsolutePath()); return new File[0]; } File[] unitTestResultFiles = findXMLFilesStartingWith(dir, "TEST-"); if (unitTestResultFiles.length == 0) { // maybe there's only a test suite result file unitTestResultFiles = findXMLFilesStartingWith(dir, "TESTS-"); } return unitTestResultFiles; }
public void collect(SensorContext context, File reportsDir) { File[] xmlFiles = getReports(reportsDir); if (xmlFiles.length > 0) { parseFiles(context, xmlFiles); } }
private void parseFiles(SensorContext context, List<File> reports) { UnitTestIndex index = new UnitTestIndex(); parseFiles(reports, index); sanitize(index); save(index, context); }
private void save(UnitTestClassReport report, InputFile inputFile, SensorContext context) { int testsCount = report.getTests() - report.getSkipped(); saveMeasure(context, inputFile, CoreMetrics.SKIPPED_TESTS, report.getSkipped()); saveMeasure(context, inputFile, CoreMetrics.TESTS, testsCount); saveMeasure(context, inputFile, CoreMetrics.TEST_ERRORS, report.getErrors()); saveMeasure(context, inputFile, CoreMetrics.TEST_FAILURES, report.getFailures()); saveMeasure(context, inputFile, CoreMetrics.TEST_EXECUTION_TIME, report.getDurationMilliseconds()); saveResults(inputFile, report); }
private void save(UnitTestIndex index, SensorContext context) { long negativeTimeTestNumber = 0; for (Map.Entry<String, UnitTestClassReport> entry : index.getIndexByClassname().entrySet()) { UnitTestClassReport report = entry.getValue(); if (report.getTests() > 0) { negativeTimeTestNumber += report.getNegativeTimeTestNumber(); Resource resource = getUnitTestResource(entry.getKey()); if (resource != null) { save(report, resource, context); } else { LOGGER.warn("Resource not found: {}", entry.getKey()); } } } if (negativeTimeTestNumber > 0) { LOGGER.warn("There is {} test(s) reported with negative time by surefire, total duration may not be accurate.", negativeTimeTestNumber); } }
private void save(UnitTestIndex index, SensorContext context) { long negativeTimeTestNumber = 0; Map<InputFile, UnitTestClassReport> indexByInputFile = mapToInputFile(index.getIndexByClassname()); for (Map.Entry<InputFile, UnitTestClassReport> entry : indexByInputFile.entrySet()) { UnitTestClassReport report = entry.getValue(); if (report.getTests() > 0) { negativeTimeTestNumber += report.getNegativeTimeTestNumber(); save(report, entry.getKey(), context); } } if (negativeTimeTestNumber > 0) { LOGGER.warn("There is {} test(s) reported with negative time by surefire, total duration may not be accurate.", negativeTimeTestNumber); } }
private static List<File> getReports(List<File> dirs, boolean reportDirSetByUser) { return dirs.stream() .map(dir -> getReports(dir, reportDirSetByUser)) .flatMap(Arrays::stream) .collect(Collectors.toList()); }
private Map<InputFile, UnitTestClassReport> mapToInputFile(Map<String, UnitTestClassReport> indexByClassname) { Map<InputFile, UnitTestClassReport> result = new HashMap<>(); indexByClassname.forEach((className, index) -> { InputFile resource = getUnitTestResource(className, index); if (resource != null) { UnitTestClassReport report = result.computeIfAbsent(resource, r -> new UnitTestClassReport()); // in case of repeated/parameterized tests (JUnit 5.x) we may end up with tests having the same name index.getResults().forEach(report::add); } else { LOGGER.debug("Resource not found: {}", className); } }); return result; }
private void parseFiles(SensorContext context, List<File> reports) { UnitTestIndex index = new UnitTestIndex(); parseFiles(reports, index); sanitize(index); save(index, context); }
private void save(UnitTestClassReport report, InputFile inputFile, SensorContext context) { int testsCount = report.getTests() - report.getSkipped(); saveMeasure(context, inputFile, CoreMetrics.SKIPPED_TESTS, report.getSkipped()); saveMeasure(context, inputFile, CoreMetrics.TESTS, testsCount); saveMeasure(context, inputFile, CoreMetrics.TEST_ERRORS, report.getErrors()); saveMeasure(context, inputFile, CoreMetrics.TEST_FAILURES, report.getFailures()); saveMeasure(context, inputFile, CoreMetrics.TEST_EXECUTION_TIME, report.getDurationMilliseconds()); saveResults(inputFile, report); }
private void save(UnitTestIndex index, SensorContext context) { long negativeTimeTestNumber = 0; Map<InputFile, UnitTestClassReport> indexByInputFile = mapToInputFile(index.getIndexByClassname()); for (Map.Entry<InputFile, UnitTestClassReport> entry : indexByInputFile.entrySet()) { UnitTestClassReport report = entry.getValue(); if (report.getTests() > 0) { negativeTimeTestNumber += report.getNegativeTimeTestNumber(); save(report, entry.getKey(), context); } } if (negativeTimeTestNumber > 0) { LOGGER.warn("There is {} test(s) reported with negative time by surefire, total duration may not be accurate.", negativeTimeTestNumber); } }
private static List<File> getReports(List<File> dirs, boolean reportDirSetByUser) { return dirs.stream() .map(dir -> getReports(dir, reportDirSetByUser)) .flatMap(Arrays::stream) .collect(Collectors.toList()); }
private Map<InputFile, UnitTestClassReport> mapToInputFile(Map<String, UnitTestClassReport> indexByClassname) { Map<InputFile, UnitTestClassReport> result = new HashMap<>(); indexByClassname.forEach((className, index) -> { InputFile resource = getUnitTestResource(className, index); if (resource != null) { UnitTestClassReport report = result.computeIfAbsent(resource, r -> new UnitTestClassReport()); // in case of repeated/parameterized tests (JUnit 5.x) we may end up with tests having the same name index.getResults().forEach(report::add); } else { LOGGER.debug("Resource not found: {}", className); } }); return result; }
private void parseFiles(SensorContext context, File[] reports) { UnitTestIndex index = new UnitTestIndex(); parseFiles(reports, index); sanitize(index); save(index, context); }
private void save(UnitTestClassReport report, Resource resource, SensorContext context) { double testsCount = report.getTests() - report.getSkipped(); saveMeasure(context, resource, CoreMetrics.SKIPPED_TESTS, report.getSkipped()); saveMeasure(context, resource, CoreMetrics.TESTS, testsCount); saveMeasure(context, resource, CoreMetrics.TEST_ERRORS, report.getErrors()); saveMeasure(context, resource, CoreMetrics.TEST_FAILURES, report.getFailures()); saveMeasure(context, resource, CoreMetrics.TEST_EXECUTION_TIME, report.getDurationMilliseconds()); double passedTests = testsCount - report.getErrors() - report.getFailures(); if (testsCount > 0) { double percentage = passedTests * 100d / testsCount; saveMeasure(context, resource, CoreMetrics.TEST_SUCCESS_DENSITY, ParsingUtils.scaleValue(percentage)); } saveResults(resource, report); }
public void collect(SensorContext context, List<File> reportsDirs, boolean reportDirSetByUser) { List<File> xmlFiles = getReports(reportsDirs, reportDirSetByUser); if (!xmlFiles.isEmpty()) { parseFiles(context, xmlFiles); } }
protected void collect(SensorContext context, File reportsDir) { LOGGER.info("parsing {}", reportsDir); surefireJavaParser.collect(context, reportsDir); }
private static File[] getReports(File dir, boolean reportDirSetByUser) { if (!dir.isDirectory()) { if(reportDirSetByUser) { LOGGER.error("Reports path not found or is not a directory: " + dir.getAbsolutePath()); } return new File[0]; } File[] unitTestResultFiles = findXMLFilesStartingWith(dir, "TEST-"); if (unitTestResultFiles.length == 0) { // maybe there's only a test suite result file unitTestResultFiles = findXMLFilesStartingWith(dir, "TESTS-"); } if(unitTestResultFiles.length == 0) { LOGGER.warn("Reports path contains no files matching TEST-.*.xml : "+dir.getAbsolutePath()); } return unitTestResultFiles; }
public void collect(SensorContext context, List<File> reportsDirs, boolean reportDirSetByUser) { List<File> xmlFiles = getReports(reportsDirs, reportDirSetByUser); if (!xmlFiles.isEmpty()) { parseFiles(context, xmlFiles); } }