Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/main/java/io/github/ktestify/config/FrameworkConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -53,7 +55,7 @@ public final class FrameworkConfig {

// Reporting
private final boolean enableReporting;
private final String reportFormat;
private final List<String> reportFormats;
private final String reportOutputDirectory;

FrameworkConfig(Config config) {
Expand Down Expand Up @@ -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.
*
* <p>{@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<String> readReportFormats(Config reportConfig) {
if (reportConfig.getValue("format").valueType() == ConfigValueType.STRING) {
return List.of(reportConfig.getString("format"));
}
return List.copyOf(reportConfig.getStringList("format"));
}

private Optional<String> getOptionalString(Config config, String path) {
if (config.hasPath(path) && !config.getIsNull(path)) {
String value = config.getString(path);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
37 changes: 27 additions & 10 deletions src/test/java/io/github/ktestify/config/FrameworkConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
}

// ==========================================
Expand Down
Loading