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