Skip to content

Commit

Permalink
Merge pull request #274 from mimbrero/fix-executor-allure-directory
Browse files Browse the repository at this point in the history
Fix Allure results directory when using RESTestRunner
  • Loading branch information
josgarmar31 authored Sep 2, 2024
2 parents 503f2a1 + 3665b1f commit 487cdb0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/main/java/es/us/isa/restest/runners/RESTestExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import es.us.isa.restest.util.ClassLoader;

import es.us.isa.restest.util.Timer;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.junit4.AllureJunit4;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.runner.JUnitCore;
Expand All @@ -28,6 +30,7 @@ public class RESTestExecutor {
private static final Logger logger = LogManager.getLogger(RESTestExecutor.class.getName());

RESTestLoader loader;
private final AllureLifecycle allureLifecycle = new AllureLifecycle();

public RESTestExecutor(String propertyFilePath) {
loader = new RESTestLoader(propertyFilePath);
Expand All @@ -45,6 +48,8 @@ public void execute() {
logger.error("Test class {} not found in {}", className, filePath);
throw new IllegalArgumentException("Test class " + className + " not found in " + filePath);
}else{
String allureResultsDirectory = loader.allureResultsPath + "/" + loader.experimentName;
System.setProperty("allure.results.directory", allureResultsDirectory);
Class<?> testClass = loadTestClass(filePath, className);
runTests(testClass);
}
Expand All @@ -59,7 +64,7 @@ private Class<?> loadTestClass(String filePath, String className) {
private void runTests(Class<?> testClass) {

JUnitCore junit = new JUnitCore();
junit.addListener(new io.qameta.allure.junit4.AllureJunit4());
junit.addListener(new AllureJunit4(this.allureLifecycle));
loader.spec = new OpenAPISpecification(loader.OAISpecPath);
loader.createStatsReportManager();
Timer.startCounting(TEST_SUITE_EXECUTION);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/es/us/isa/restest/runners/RESTestLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class RESTestLoader {
Boolean logToFile; // If 'true', log messages will be printed to external files
Boolean executeTestCases; // If 'false', test cases will be generated but not executed
Boolean allureReports; // If 'true', Allure reports will be generated
String allureResultsPath; // Path to Allure results
String allureReportsPath; // Path to Allure reports
Boolean checkTestCases; // If 'true', test cases will be checked with OASValidator before executing them
String proxy; // Proxy to use for all requests in format host:port
Expand Down Expand Up @@ -144,7 +145,7 @@ public IWriter createWriter() {
public AllureReportManager createAllureReportManager() {
AllureReportManager arm = null;
if(executeTestCases) {
String allureResultsDir = readProperty("allure.results.dir") + "/" + experimentName;
String allureResultsDir = allureResultsPath + "/" + experimentName;
String allureReportDir = allureReportsPath + "/" + experimentName;

// Delete previous results (if any)
Expand Down Expand Up @@ -222,6 +223,8 @@ public void readProperties() {
}
logger.info("Allure reports: {}", allureReports);

allureResultsPath = readProperty("allure.results.dir");
logger.info("Allure results path: {}", allureResultsPath);

allureReportsPath = readProperty("allure.report.dir");
logger.info("Allure reports path: {}", allureReportsPath);
Expand Down

0 comments on commit 487cdb0

Please sign in to comment.