Skip to content

Commit

Permalink
chore: Use single report output directory
Browse files Browse the repository at this point in the history
- Make sure to us single output directory for generated reports in particular when running Citrus via JBang
  • Loading branch information
christophd committed Nov 12, 2024
1 parent 578595a commit f3dca6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private TestReporterSettings() {

private static final String REPORT_DIRECTORY_PROPERTY = "citrus.report.directory";
private static final String REPORT_DIRECTORY_ENV = "CITRUS_REPORT_DIRECTORY";
private static final String REPORT_DIRECTORY_DEFAULT = "target/citrus-reports";

/**
* Get setting if report should automatically clear all test results after finishing the test suite. Default value
Expand All @@ -57,6 +58,10 @@ public static boolean isIgnoreErrors() {
*/
public static String getReportDirectory() {
return System.getProperty(REPORT_DIRECTORY_PROPERTY, System.getenv(REPORT_DIRECTORY_ENV) != null ?
System.getenv(REPORT_DIRECTORY_ENV) : "target/citrus-reports");
System.getenv(REPORT_DIRECTORY_ENV) : REPORT_DIRECTORY_DEFAULT);
}

public static void setReportDirectory(String dir) {
System.setProperty(REPORT_DIRECTORY_PROPERTY, dir);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.citrusframework.main.TestRunConfiguration;
import org.citrusframework.main.scan.ClassPathTestScanner;
import org.citrusframework.main.scan.JarFileTestScanner;
import org.citrusframework.report.TestReporterSettings;
import org.citrusframework.testng.main.TestNGCitrusTest;
import org.citrusframework.util.StringUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -64,6 +65,7 @@ public TestNGEngine(TestRunConfiguration configuration) {

public void run() {
TestNG testng = new TestNG();
testng.setOutputDirectory(TestReporterSettings.getReportDirectory() + "/" + TestNG.DEFAULT_OUTPUTDIR);

for (ITestNGListener listener : listeners) {
testng.addListener(listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.citrusframework.main.TestEngine;
import org.citrusframework.main.TestRunConfiguration;
import org.citrusframework.report.TestReporter;
import org.citrusframework.report.TestReporterSettings;
import org.citrusframework.report.TestResults;
import org.citrusframework.util.FileUtils;
import picocli.CommandLine.Command;
Expand All @@ -63,14 +64,14 @@ public class Run extends CitrusCommand {
"^\\s*public class\\s+([a-zA-Z0-9]*)[\\s+|;].*$", Pattern.MULTILINE);

@Option(names = { "--logging" }, defaultValue = "true", description = "Can be used to turn off logging")
private boolean logging = true;
private final boolean logging = true;

@Option(names = { "--logging-level" }, completionCandidates = LoggingSupport.LoggingLevels.class,
defaultValue = "info", description = "Logging level")
private String loggingLevel;

@Option(names = { "--logging-color" }, defaultValue = "true", description = "Use colored logging")
private boolean loggingColor = true;
private final boolean loggingColor = true;

@Parameters(description = "The test file(s) to run. If no files specified then application.properties is used as source for which files to run.",
arity = "0..9", paramLabel = "<files>", parameterConsumer = FilesConsumer.class)
Expand All @@ -89,6 +90,7 @@ public Integer call() throws Exception {

private int run() throws Exception {
File work = new File(WORK_DIR);
TestReporterSettings.setReportDirectory(WORK_DIR + "/citrus-reports");
removeDir(work);
if (!work.mkdirs()) {
System.err.println("Failed to create working directory " + WORK_DIR);
Expand Down Expand Up @@ -207,11 +209,7 @@ private boolean skipFile(String name) {

String on = FileUtils.getBaseName(name);
on = on.toLowerCase(Locale.ROOT);
if (on.endsWith("readme")) {
return true;
}

return false;
return on.endsWith("readme");
}

private static void removeDir(File d) {
Expand Down

0 comments on commit f3dca6c

Please sign in to comment.