diff --git a/src/main/java/io/github/ktestify/config/FrameworkConfig.java b/src/main/java/io/github/ktestify/config/FrameworkConfig.java index d16a9c7..d68d728 100644 --- a/src/main/java/io/github/ktestify/config/FrameworkConfig.java +++ b/src/main/java/io/github/ktestify/config/FrameworkConfig.java @@ -16,9 +16,11 @@ package io.github.ktestify.config; import com.typesafe.config.Config; +import com.typesafe.config.ConfigValueType; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; +import java.util.List; import java.util.Optional; import lombok.Getter; @@ -53,7 +55,7 @@ public final class FrameworkConfig { // Reporting private final boolean enableReporting; - private final String reportFormat; + private final List reportFormats; private final String reportOutputDirectory; FrameworkConfig(Config config) { @@ -81,10 +83,27 @@ public final class FrameworkConfig { // Reporting Config reportConfig = config.getConfig("reporting"); this.enableReporting = reportConfig.getBoolean("enabled"); - this.reportFormat = reportConfig.getString("format"); + this.reportFormats = readReportFormats(reportConfig); this.reportOutputDirectory = reportConfig.getString("output"); } + /** + * Reads the configured report formats. + * + *

{@code ktestify.framework.reporting.format} accepts either a single string ({@code format = "html"}) or an + * array of strings ({@code format = ["html", "json"]}). A single string is wrapped into a one-element list so + * existing configurations keep working. + * + * @param reportConfig the reporting config section + * @return the configured report formats, never null + */ + private static List readReportFormats(Config reportConfig) { + if (reportConfig.getValue("format").valueType() == ConfigValueType.STRING) { + return List.of(reportConfig.getString("format")); + } + return List.copyOf(reportConfig.getStringList("format")); + } + private Optional getOptionalString(Config config, String path) { if (config.hasPath(path) && !config.getIsNull(path)) { String value = config.getString(path); diff --git a/src/main/resources/application.conf.template b/src/main/resources/application.conf.template index 0e406ee..8417cf9 100644 --- a/src/main/resources/application.conf.template +++ b/src/main/resources/application.conf.template @@ -89,7 +89,8 @@ ktestify { # Reporting settings reporting { enabled = true - format = "html" + # One or more report formats: html, json, pretty + format = ["html"] output = "target/test-output" } } diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 19835b3..747074f 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -160,8 +160,8 @@ ktestify { # Reporting settings reporting { enabled = true - # Format: html, json, cucumber - format = "html" + # Report formats: html, json, pretty. Single value or array, e.g. ["html", "json"] + format = ["html"] # Directory for test output/reports output = "src/target/reports/report.html" output = ${?KTESTIFY_OUTPUT_DIR} diff --git a/src/test/java/io/github/ktestify/config/FrameworkConfigTest.java b/src/test/java/io/github/ktestify/config/FrameworkConfigTest.java index 46cf0d6..0504a38 100644 --- a/src/test/java/io/github/ktestify/config/FrameworkConfigTest.java +++ b/src/test/java/io/github/ktestify/config/FrameworkConfigTest.java @@ -20,11 +20,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Duration; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import java.util.List; +import org.junit.jupiter.api.*; /** * Comprehensive unit tests for FrameworkConfig. Tests all getters, timeout conversions, path resolution, and edge @@ -342,9 +339,9 @@ void shouldGetEnableReporting() { } @Test - @DisplayName("Should get report format") - void shouldGetReportFormat() { - assertEquals("html", frameworkConfig.getReportFormat()); + @DisplayName("Should get default report formats") + void shouldGetDefaultReportFormats() { + assertEquals(List.of("html"), frameworkConfig.getReportFormats()); } @Test @@ -360,16 +357,36 @@ void shouldHandleDisabledReporting() { @Test @DisplayName("Should handle different report formats") void shouldHandleDifferentReportFormats() { - String[] formats = {"html", "json", "cucumber"}; + String[] formats = {"html", "json", "pretty"}; for (String format : formats) { KtestifyConfig config = ConfigBuilder.create() .set("ktestify.framework.reporting.format", format) .build(); - assertEquals(format, config.getFramework().getReportFormat()); + assertEquals(List.of(format), config.getFramework().getReportFormats()); } } + + @Test + @DisplayName("Should accept an array of report formats") + void shouldAcceptArrayOfReportFormats() { + KtestifyConfig config = ConfigBuilder.create() + .set("ktestify.framework.reporting.format", List.of("html", "json")) + .build(); + + assertEquals(List.of("html", "json"), config.getFramework().getReportFormats()); + } + + @Test + @DisplayName("Should handle an empty array of report formats") + void shouldHandleEmptyArrayOfReportFormats() { + KtestifyConfig config = ConfigBuilder.create() + .set("ktestify.framework.reporting.format", List.of()) + .build(); + + assertTrue(config.getFramework().getReportFormats().isEmpty()); + } } // ==========================================