001package org.hl7.fhir.utilities.tests.execution; 002 003import java.io.PrintStream; 004 005import org.hl7.fhir.utilities.tests.execution.junit5.JUnit5ModuleTestExecutor; 006import org.slf4j.Logger; 007 008public abstract class ModuleTestExecutor { 009 private static final String FAILURE_SUMMARY_TEMPLATE = "Test failures for module %s (%d):"; 010 private static final String STARTING_TEST_TEMPLATE = "Starting: %s"; 011 012 private static final String FINISHED_TEST_TEMPLATE = "Finished: %s with result: %s"; 013 private static final String FAILED_TEST_TEMPLATE = "Failed Test ID: %s"; 014 015 /** 016 * Utility method to print the summary of execution in human-readable 017 * format. 018 * <br/> 019 * Any test failures are listed using the same unique IDs output in 020 * the {@link JUnit5ModuleTestExecutor#executeTests(Logger, String)} 021 * method. 022 * 023 * @param log the log to write summary data to. 024 * @param testExecutionSummary the test summary 025 * @param moduleName the module name 026 */ 027 public static void logSummary(Logger log, CliTestSummary testExecutionSummary, String moduleName) { 028 log.info("\n" + String.format(FAILURE_SUMMARY_TEMPLATE, moduleName, testExecutionSummary.getTestsFailedCount())); 029 for (CliTestException failure : testExecutionSummary.getExceptions()) { 030 log.info("\t" + failure.getTestId() + ": " + failure.getException().getMessage()); 031 } 032 log.info(""); 033 } 034 035 public static void printTestStarted(Logger log, String displayName) { 036 log.info(String.format(STARTING_TEST_TEMPLATE, displayName)); 037 } 038 039 public static void printTestFailed(Logger log, String uniqueIdentifier, Throwable throwable) { 040 041 log.info(String.format(FAILED_TEST_TEMPLATE, uniqueIdentifier)); 042 if (throwable != null) { 043 throwable.printStackTrace(System.out); 044 } 045 } 046 047 public static void printTestFinished(Logger log, String displayName, String status) { 048 log.info(String.format(FINISHED_TEST_TEMPLATE, displayName, status)); 049 } 050 051 public abstract String getModuleName(); 052 053 public abstract CliTestSummary executeTests(Logger log, String classNameFilter); 054 055}